SERVER_NAME and fastcgi

KyleChristensen nginx-forum at
Thu Sep 16 05:34:56 MSD 2010

Forgive me if this has been covered before, but I didn't see anything
while searching.

I have a server setup similar to:

server {
	listen	80;
	rewrite "^(.*)$"$1       permanent;

server {
	listen	80;
	server_name *;
	server_name_in_redirect off;


I had some issues with nginx redirecting to * when people
would omit a trailing / on physical directories in requests, the only
fix I was able to ascertain was setting it up as I have mentioned.

At any rate, if a client makes a request that bypasses our loadbalancer
directly via, it gets caught by the second server block
as intended. The problem however is that $server_name gets set to the
first match in the server_name directive (as mentioned in the
documentation). My fastcgi_param for SERVER_NAME is set to $server_name
(the default).

The problem is that I need the ability to discern that someone is
hitting a server directly via $_SERVER['SERVER_NAME'], and under this
default configuration I am unable to do so since even direct requests to
webservers end up having $server_name set to, rather than
what the Host: was set to (

I understand that there is also the $host variable, but I was not sure
what the best practice is as far as reliably duplicating the SERVER_NAME
functionality of Apache.

Any help would be appreciated!


Posted at Nginx Forum:,130806,130806#msg-130806

More information about the nginx mailing list