# Best way to handle preprod server\_names

**URL:** <https://www.ruby-forum.com/t/best-way-to-handle-preprod-server-names/219791>\
**Category:** NGINX\
**Created:** [May 16, 2012, 11:09am UTC](https://www.ruby-forum.com/t/best-way-to-handle-preprod-server-names/219791 "2012-05-16T11:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 16, 2012, 11:09am UTC](https://www.ruby-forum.com/t/best-way-to-handle-preprod-server-names/219791/1 "2012-05-16T11:09:33Z")

</div>

Hi,

I’m going to migrate a lots of vhosts from Squid+Apache2 to NginX, step  
by step.  
First step is to migrate just NginX and few static vhosts.

Actually there is ~600 domains x 5 vhosts + equivalent for preprod. So I  
wrote a NginX vhost for “.mydomain1.com .mydomain2.com” and so on with  
the 600 domains.

Question is, how the best practices to have this domains for our preprod  
which looks like “.preprod.mydomain1.com” for each domains.

Preprod has specific config like gzip disabled (for internals  
purpose…).

Actually, prod’s config looks like :  
server {  
server\_name .mydomain1.com; # main domain  
include /etc/nginx/domains.conf;  
server\_name\_in\_redirect off;  
include common/prod.conf  
}

And domains.conf :  
server\_name  
.mydomain1.com  
.mydomain2.com  
…  
;

Preprod could have this config :  
server {  
server\_name .preprod.mydomain1.com; # main domain  
include  
/etc/nginx/preprod\_domains.conf;  
server\_name\_in\_redirect off;  
include common/preprod.conf  
}

Which means (600 x 5 x 2) vhosts…

Is there a better way ?

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [May 16, 2012, 6:49pm UTC](https://www.ruby-forum.com/t/best-way-to-handle-preprod-server-names/219791/2 "2012-05-16T18:49:01Z")

</div>

Hello,

Typically, I would use one directory per host to serve content from each  
domain and use one config file per generic type:  
http {  
listen 80;  
root /var/www/$host;

server { # Include that section from a separate file  
server\_name ~\[1\]+(.[[:alnum:]]+  
)_.preprod.domain[0-9]_.com$;  
# Pre-production rules  
}

server { # Include that section from a separate file  
server\_name  
~\[2\]+(.[[:alnum:]]+)_(!.preprod).domain[0-9]_  
.com$;  
# Production rules  
}  
}

You can then create server bloc listening to specific subdomains for  
particular case, i.e.:  
server {  
server\_name [test.preprod.domain42.com](http://test.preprod.domain42.com);

# Rules here have higher priority than the generic rules since the

server\_name uses an exact match comparison  
}

## You will have to work further on regex to be sure they do what you want them to do. ;o)

_B. R._

* * *

1. [:alnum:] 

2. [:alnum:]

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [May 18, 2012, 9:25am UTC](https://www.ruby-forum.com/t/best-way-to-handle-preprod-server-names/219791/3 "2012-05-18T09:25:23Z")

</div>

Le 16/05/2012 18:47, B.R. a crit :

> Hello,
> 
> Typically, I would use one directory per host to serve content from  
> each domain and use one config file per generic type:

Hello,

thanks, but I can as I have to _migrate_ the actual config.  
I’m going to generate server\_name config in separates files, then  
include them in server {} config like :

server {  
server\_name [domain1.com](http://domain1.com); # main domain  
include prod\_domains.conf;  
include commonrules.conf;  
include prod\_rules.conf;  
}  
server {  
server\_name [preprod.domain1.com](http://preprod.domain1.com); # main domain  
include preprod\_domains.conf;  
include commonrules.conf;  
include preprod\_rules.conf;  
}

But the server\_names list will be huge…
