# Server\_name host order

**URL:** <https://www.ruby-forum.com/t/server-name-host-order/214149>\
**Category:** NGINX\
**Created:** [November 23, 2011, 11:31am UTC](https://www.ruby-forum.com/t/server-name-host-order/214149 "2011-11-23T11:31:32Z")\
**Posts on this page:** 3\
**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:** [November 23, 2011, 11:31am UTC](https://www.ruby-forum.com/t/server-name-host-order/214149/1 "2011-11-23T11:31:32Z")

</div>

Hello, I would like to know if this is correct

Will NGINX allways return the first of the provided hostname name in  
from the `server_name` as beign the “SERVER\_NAME”,

eg server\_name hostname1 hostname2;

I have two server blocks in this example

server {  
listen 80;  
server\_name [www.example.co.uk](http://www.example.co.uk) \*.example.co.uk;  
}

the URI = [http://something.example.co.uk/](http://something.example.co.uk/)

// PHP APPLICATION --------------  
I see as expected `SERVER_NAME` and `HTTP_HOST`

## SERVER\_PORT =\> 80 SERVER\_NAME =\> [www.example.co.uk](http://www.example.co.uk) HTTP\_HOST =\> [something.example.co.uk](http://something.example.co.uk)

server {  
listen 443;  
server\_name [www.example.co.uk](http://www.example.co.uk) [secure.example.co.uk](http://secure.example.co.uk);  
}

// PHP APPLICATION --------------  
again the `SERVER_NAME` and `HTTP_HOST` as i would expect

the URI = [https://secure.example.co.uk/](https://secure.example.co.uk/)

// SERVER\_PORT =\> 443  
// SERVER\_NAME =\> [www.example.co.uk](http://www.example.co.uk)  
// HTTP\_HOST =\> [secure.example.co.uk](http://secure.example.co.uk)

Posted at Nginx Forum:

> **[server\_name host order](https://forum.nginx.org/read.php?2,218786,218786#msg-218786)**
>
> Hello, I would like to know if this is correct Will NGINX allways return the first of the provided hostname name in from the \`server\_name\` as beign the "SERVER\_NAME", eg server\_name hostname1 hostname2; I have two server blocks in this...

---

<div class="post-metadata">

**Author:** ![token](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@token](https://www.ruby-forum.com/u/token)\
**Post date:** [November 23, 2011, 2:44pm UTC](https://www.ruby-forum.com/t/server-name-host-order/214149/2 "2011-11-23T14:44:17Z")

</div>

Hello!

On Wed, Nov 23, 2011 at 05:30:46AM -0500, token wrote:

> Hello, I would like to know if this is correct
> 
> Will NGINX allways return the first of the provided hostname name in  
> from the `server_name` as beign the “SERVER\_NAME”,
> 
> eg server\_name hostname1 hostname2;

The $server\_name variable is always first name as defined by the  
“server\_name” directive in the server{} in question.

With default fastcgi\_params as shipped with nginx, SERVER\_NAME as  
passed to php via fastcgi will be set to $server\_name, i.e. first  
name defined with the “server\_name” directive.

> I see as expected `SERVER_NAME` and `HTTP_HOST`
> 
> // PHP APPLICATION --------------  
> again the `SERVER_NAME` and `HTTP_HOST` as i would expect
> 
> the URI = [https://secure.example.co.uk/](https://secure.example.co.uk/)
> 
> // SERVER\_PORT =\> 443  
> // SERVER\_NAME =\> [www.example.co.uk](http://www.example.co.uk)  
> // HTTP\_HOST =\> [secure.example.co.uk](http://secure.example.co.uk)

Yes, this is correct and expected behaviour.

Maxim D.

---

<div class="post-metadata">

**Author:** ![token](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@token](https://www.ruby-forum.com/u/token)\
**Post date:** [November 23, 2011, 2:56pm UTC](https://www.ruby-forum.com/t/server-name-host-order/214149/3 "2011-11-23T14:56:04Z")

</div>

Thank you for clearing this up. Thanks Again Maxim!

> Hello!

> On Wed, Nov 23, 2011 at 05:30:46AM -0500, token wrote:

> Hello, I would like to know if this is correct
> 
> Will NGINX allways return the first of the provided hostname name in  
> from the `server_name` as beign the “SERVER\_NAME”,
> 
> eg server\_name hostname1 hostname2;

> The $server\_name variable is always first name as defined by the  
> “server\_name” directive in the server{} in question.

> With default fastcgi\_params as shipped with nginx, SERVER\_NAME as  
> passed to php via fastcgi will be set to $server\_name, i.e. first  
> name defined with the “server\_name” directive.

> I see as expected `SERVER_NAME` and `HTTP_HOST`
> 
> // PHP APPLICATION --------------  
> again the `SERVER_NAME` and `HTTP_HOST` as i would expect
> 
> the URI = [https://secure.example.co.uk/](https://secure.example.co.uk/)
> 
> // SERVER\_PORT =\> 443  
> // SERVER\_NAME =\> [www.example.co.uk](http://www.example.co.uk)  
> // HTTP\_HOST =\> [secure.example.co.uk](http://secure.example.co.uk)

> Yes, this is correct and expected behaviour.

> Maxim D.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,218786,218825#msg-218825](http://forum.nginx.org/read.php?2,218786,218825#msg-218825)
