SERVER_NAME vs HTTP_HOST

If server_name is something like “*.mydomain.com”, $server_name is exactly “*.mydomain.com”. If $server_name is passed on to fastcgi_param as SERVER_NAME, in the program, for example, php $_SERVER[‘SERVER_NAME’] will be exactly “*.mydomain.com”. However, _SERVER[“HTTP_HOST”] shows the value most of us would expect, i.e. the host name in the address bar.

In Nginx, I have set up a mechanism to install some popular scripts once, and use in multiple websites. I do not want people to find these websites are run under one roof. But if I write multiple websites in one line:


server_name domain1.com domain2.com domain3.com;

$_SERVER[‘SERVER_NAME’] is always assigned domain1.com no matter the host is domain2.com or domain3.com.

To avoid that, I have to break three websites into three server block in nginx.

$_SERVER[‘HTTP_HOST’] is always the host. But I can not control how people write the script. Breaking hosts into separate server blocks is recommended.

Leave a Reply

Your email address will not be published. Required fields are marked *