Possible bug in value of $server_name variable

Francis Daly francis at daoine.org
Thu Mar 8 18:40:56 UTC 2012


On Thu, Mar 08, 2012 at 12:55:15PM -0500, Kaimei wrote:

Hi there,

> Is this is bug or how to get the real hostname the user connect to ?

The nginx variable $server_name is the first name in the server_name
directive list.

The nginx variable $http_host is the Host: header sent by the client.

The nginx variable $host is $http_host if it is defined, and $server_name
if not.

The typical nginx fastcgi configuration will set SERVER_NAME to
$server_name (within fastcgi.conf) and HTTP_HOST to http_host (because
that's what happens to client headers). So you can check those in
your script.

If you wish, you can add your own "fastcgi_param HOST $host" setting
and check that, or you could set SERVER_NAME to be $host and continue
checking that one.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list