Skip to content

Question : [Nginx] How to change value of $_SERVER['SERVER_NAME'] from nginx conf ? #227

@wollanup

Description

@wollanup

in vhost.conf we have :

server_name  _ <ALIAS_DOMAIN> docker;

in /opt/docker/etc/nginx/vhost.conf, in a running container, I have the substitution of <ALIAS_DOMAIN> working well, but in a PHP app, the value of $_SERVER['SERVER_NAME'] is still _, as it should be.

What would be the best approach to get my WEB_ALIAS_DOMAIN env var used in PHP's $_SERVER['SERVER_NAME'] ?

I tried to write

fastcgi_param SERVER_NAME <ALIAS_DOMAIN>;

in a conf file in vhost.common.d but it does'nt work.

Thanks

Activity

changed the title [-]Question : [Nginx] How to change "server_name" ?[/-] [+]Question : [Nginx] How to change value of $_SERVER['SERVER_NAME'] from nginx conf ?[/+] on Apr 19, 2018
nubam

nubam commented on May 9, 2018

@nubam

I am experiencing the exact same error.
PHP's sever name variable is set to _ on my test site.

In a workaround, I added the following code to /vhost.common.d/10-php.conf to get the correct domain name inside the container.

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME     $request_filename;
    fastcgi_param SERVER_NAME $host;
}
vertexvaar

vertexvaar commented on Jan 18, 2019

@vertexvaar
Contributor

Another workaround: Overwrite vhost.conf in your Dockerfile and set the expected server name as first server_name argument.

The real question is however why there is a _ in the first place?

thanhtoan1196

thanhtoan1196 commented on Dec 1, 2023

@thanhtoan1196

Any updates?
How to change $_SERVER without editing vhost manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wollanup@vertexvaar@PanadeEdu@thanhtoan1196@nubam

        Issue actions

          Question : [Nginx] How to change value of $_SERVER['SERVER_NAME'] from nginx conf ? · Issue #227 · webdevops/Dockerfile