# Nginx to server secure and not secure traffic

**URL:** <https://www.ruby-forum.com/t/nginx-to-server-secure-and-not-secure-traffic/223360>\
**Category:** NGINX\
**Created:** [October 1, 2012, 6:23pm UTC](https://www.ruby-forum.com/t/nginx-to-server-secure-and-not-secure-traffic/223360 "2012-10-01T18:23:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 1, 2012, 6:23pm UTC](https://www.ruby-forum.com/t/nginx-to-server-secure-and-not-secure-traffic/223360/1 "2012-10-01T18:23:43Z")

</div>

We have secure and no secure domains for our website e.g.  
[secure.xyz.com](http://secure.xyz.com)  
and [xyz.com](http://xyz.com)

I used following like to make single server handle both port 80 and 443  
traffic.

[http://nginx.org/en/docs/http/configuring\_https\_servers.html#single\_http\_https\_server](http://nginx.org/en/docs/http/configuring_https_servers.html#single_http_https_server)

server {  
listen 80;  
listen 443 ssl;  
server\_name [secure.xyz.com](http://secure.xyz.com)[xyz.com](http://xyz.com);  
…  
ssl\_certificate secure.xyz.com.crt;  
ssl\_certificate\_key secure.xyz.com.key;  
…  
}

Every thing works fine except that $\_SERVER variables ‘SERVER\_NAME’ is  
set  
to ‘[secure.xyz.com](http://secure.xyz.com)’ .

My question is :

1. Does Nginx always picks the first server from the config …  
irrespective  
of what client has requested and passes to proxy (php-fpm)?

2. We have a lot of rules, so if we create two separate server (as per  
following) do I need to copy the rules in both places? It there any  
maintainable way, like ‘include /common\_rules.conf’?

server {  
listen 443;  
server\_name [secure.xyz.com](http://secure.xyz.com);  
ssl on;  
ssl\_certificate secure.xyz.com.crt;  
…  
include common\_rules.conf; ===\>???  
}

server {  
listen 80;  
server\_name [xyz.com](http://xyz.com);  
…  
include common\_rules.conf; ===\>???  
}

Any help is highly appreciated.

Posted at Nginx Forum:

> **[Nginx to server secure and not secure traffic](https://forum.nginx.org/read.php?2,231295,231295#msg-231295)**
>
> We have secure and no secure domains for our website e.g. secure.xyz.com and xyz.com I used following like to make single server handle both port 80 and 443 traffic....

---

<div class="post-metadata">

**Author:** ![hsrmmr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@hsrmmr](https://www.ruby-forum.com/u/hsrmmr)\
**Post date:** [October 1, 2012, 9:34pm UTC](https://www.ruby-forum.com/t/nginx-to-server-secure-and-not-secure-traffic/223360/2 "2012-10-01T21:34:16Z")

</div>

## Hi. hsrmmr Wrote:

> My question is :
> 
> 1. Does Nginx always picks the first server from the config …  
> irrespective of what client has requested and passes to proxy  
> (php-fpm)?

First is actually the server name, and others - is just aliases.  
If you want to send requested hostname to backend - use $hostname  
instead.

> 1. We have a lot of rules, so if we create two separate server (as per  
> following) do I need to copy the rules in both places? It there any  
> maintainable way, like ‘include /common\_rules.conf’?

Yes you can.  
Just “include conf/share\_config.conf;”

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

---

<div class="post-metadata">

**Author:** ![hsrmmr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@hsrmmr](https://www.ruby-forum.com/u/hsrmmr)\
**Post date:** [October 2, 2012, 6:30am UTC](https://www.ruby-forum.com/t/nginx-to-server-secure-and-not-secure-traffic/223360/3 "2012-10-02T06:30:45Z")

</div>

Yes you can.  
Just “include conf/share\_config.conf;”

==\> I created conf files with locations (which are common), however  
after  
including Nginx gives error saying " ‘location’ directive is not allowed  
here ".  
Is there something I am missing?

Posted at Nginx Forum:

> **[Re: Nginx to server secure and not secure traffic](https://forum.nginx.org/read.php?2,231295,231303#msg-231303)**
>
> We have secure and no secure domains for our website e.g. secure.xyz.com and xyz.com I used following like to make single server handle both port 80 and 443 traffic....

---

<div class="post-metadata">

**Author:** ![hsrmmr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b19c9b/32.png) [@hsrmmr](https://www.ruby-forum.com/u/hsrmmr)\
**Post date:** [October 2, 2012, 7:03am UTC](https://www.ruby-forum.com/t/nginx-to-server-secure-and-not-secure-traffic/223360/4 "2012-10-02T07:03:28Z")

</div>

Include common\_rules.conf works properly now. The problem was that the  
.conf  
file was also getting included in ‘http’ directive, so it was  
complaining  
about location directive being invalid.

Thanks !

Posted at Nginx Forum:

> **[Re: Nginx to server secure and not secure traffic](https://forum.nginx.org/read.php?2,231295,231304#msg-231304)**
>
> We have secure and no secure domains for our website e.g. secure.xyz.com and xyz.com I used following like to make single server handle both port 80 and 443 traffic....
