# SERVER\_NAME and fastcgi

**URL:** <https://www.ruby-forum.com/t/server-name-and-fastcgi/195063>\
**Category:** NGINX\
**Created:** [September 16, 2010, 3:35am UTC](https://www.ruby-forum.com/t/server-name-and-fastcgi/195063 "2010-09-16T03:35:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KyleChristensen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/edb3f5/32.png) [@KyleChristensen](https://www.ruby-forum.com/u/KyleChristensen)\
**Post date:** [September 16, 2010, 3:35am UTC](https://www.ruby-forum.com/t/server-name-and-fastcgi/195063/1 "2010-09-16T03:35:58Z")

</div>

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](http://domain.com) [someotherdomain.com](http://someotherdomain.com) [somethirddomain.com](http://somethirddomain.com);  
rewrite “^(.\*)$” [http://www.domain.com$1](http://www.domain.com$1) permanent;  
}

server {  
listen 80;  
server\_name [www.domain.com](http://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](http://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](http://www.domain.com), rather than  
what the Host: was set to ([wwwX.domain.com](http://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.

Any help would be appreciated!

Thanks,  
-Kyle

Posted at Nginx Forum:

> **[SERVER\_NAME and fastcgi](https://forum.nginx.org/read.php?2,130806,130806#msg-130806)**
>
> 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://

---

<div class="post-metadata">

**Author:** ![KyleChristensen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/edb3f5/32.png) [@KyleChristensen](https://www.ruby-forum.com/u/KyleChristensen)\
**Post date:** [September 16, 2010, 9:59am UTC](https://www.ruby-forum.com/t/server-name-and-fastcgi/195063/2 "2010-09-16T09:59:19Z")

</div>

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

> fix I was able to ascertain was setting it up as I have mentioned.  
> default configuration I am unable to do so since even direct requests to  
> webservers end up having $server\_name set to [www.domain.com](http://www.domain.com), rather than  
> what the Host: was set to ([wwwX.domain.com](http://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 S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
