My configuration file has a server
directive block that begins with...
server {
server_name www.example1.com www.example2.com www.example3.com;
...in order to allow the site to be accessed with different domain names.
However PHP's $_SERVER['SERVER_NAME']
always returns the first entry of server_name
, in this case http://www.example1.com
So I have no way from the PHP code to know which domain the user used to access the site.
Is there any way to tell nginx/fastcgi to pass the real domain name used to access the site?
The only solution I've found so far is to repeat the entire server
block for each domain with a distinct server_name
entry but obviously I'm looking for a better one.
Set
SERVER_NAME
to use$host
in yourfastcgi_params
configuration.Source: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_param
This is intended and the proper solution is to use
$_SERVER['HTTP_HOST']
in your code instead.You should interpret
SERVER_NAME
as a verified server-name, andHTTP_HOST
as user-input which can be modified quite easily, and thus shouldn't be trusted.