# Possible bug in value of $server\_name variable

**URL:** <https://www.ruby-forum.com/t/possible-bug-in-value-of-server-name-variable/217689>\
**Category:** NGINX\
**Created:** [March 8, 2012, 6:55pm UTC](https://www.ruby-forum.com/t/possible-bug-in-value-of-server-name-variable/217689 "2012-03-08T18:55:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 8, 2012, 6:55pm UTC](https://www.ruby-forum.com/t/possible-bug-in-value-of-server-name-variable/217689/1 "2012-03-08T18:55:39Z")

</div>

I have “server\_name _.domain.tld" in my config file and tried to get the  
correct virtual host the user connected to with the help of a php script  
but “$\_SERVER[‘SERVER\_NAME’]” returned "_.domain.tld” instead of  
“something.domain.tld” when I connect to it.

When I use “.domain.tld” instead of “\*.domain.tld” I get “domain.tld” as  
the hostname.

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

Posted at Nginx Forum:

> **[Possible bug in value of $server\_name variable](https://forum.nginx.org/read.php?2,223642,223642#msg-223642)**
>
> I have "server\_name \*.domain.tld" in my config file and tried to get the correct virtual host the user connected to with the help of a php script but "$\_SERVER\['SERVER\_NAME'\]" returned "\*.domain.tld" instead of...

---

<div class="post-metadata">

**Author:** ![Kaimei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/da6949/32.png) [@Kaimei](https://www.ruby-forum.com/u/Kaimei)\
**Post date:** [March 8, 2012, 7:41pm UTC](https://www.ruby-forum.com/t/possible-bug-in-value-of-server-name-variable/217689/2 "2012-03-08T19:41:45Z")

</div>

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 D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
