Dockerfile icon indicating copy to clipboard operation
Dockerfile copied to clipboard

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

Open wollanup opened this issue 6 years ago • 3 comments

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

wollanup avatar Apr 19 '18 10:04 wollanup

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;
}

nubam avatar May 09 '18 10:05 nubam

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?

vertexvaar avatar Jan 18 '19 13:01 vertexvaar

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

thanhtoan1196 avatar Dec 01 '23 09:12 thanhtoan1196