Welcome! Log In Create A New Profile


Re: SERVER_NAME and fastcgi

September 16, 2010 04:04AM
On Wed, Sep 15, 2010 at 09:34:56PM -0400, KyleChristensen wrote:

> 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;
> server_name domain.com someotherdomain.com somethirddomain.com;
> rewrite "^(.*)$" http://www.domain.com$1 permanent;
> }
> server {
> listen 80;
> server_name www.domain.com *.domain.com;
> server_name_in_redirect off;
> }
> I had some issues with nginx redirecting to *.domain.com 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 wwwX.domain.com, 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 www.domain.com, rather than
> what the Host: was set to (wwwX.domain.com).
> 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.

$server_name value is the first name in a server_name directive,
$http_host value is a value of a "Host" header line,
$host value is a value of a "Host" header line OR, if there is not
the header line, is a value of the $server_name.

Igor Sysoev

nginx mailing list
Subject Author Posted

SERVER_NAME and fastcgi

KyleChristensen September 15, 2010 09:34PM

Re: SERVER_NAME and fastcgi

Igor Sysoev September 16, 2010 04:04AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 289
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready