# Unique server for all domains or a server per domain?

**URL:** <https://www.ruby-forum.com/t/unique-server-for-all-domains-or-a-server-per-domain/216599>\
**Category:** NGINX\
**Created:** [February 9, 2012, 1:03am UTC](https://www.ruby-forum.com/t/unique-server-for-all-domains-or-a-server-per-domain/216599 "2012-02-09T01:03:38Z")\
**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:** [February 9, 2012, 1:03am UTC](https://www.ruby-forum.com/t/unique-server-for-all-domains-or-a-server-per-domain/216599/1 "2012-02-09T01:03:38Z")

</div>

Hello,

I am currently using a unique server conf for all my domains.  
When I wanna restrain certain activity to certain domains  
(subdirectories,  
URL rewriting, etc.) I do not have other choice than using ‘if’ on the  
$host variable leading to some complications due to the unreliable  
nature  
of the ‘if’ clause.  
The directory from which the content is served is determined by the  
hostname.

## On the other side, is using several servers to listen on several domains the best solution? Since NGinx is event-based and not client-based maybe that’s not a problem anymore… But not so long ago I was stuck with Apache. I still need to get used to that (great!) change.

_B. R._

---

<div class="post-metadata">

**Author:** ![B.R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@B.R](https://www.ruby-forum.com/u/B.R)\
**Post date:** [February 9, 2012, 7:02pm UTC](https://www.ruby-forum.com/t/unique-server-for-all-domains-or-a-server-per-domain/216599/2 "2012-02-09T19:02:39Z")

</div>

09 февраля 2012, 04:03 от “B.R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I am currently using a unique server conf for all my domains.  
> When I wanna restrain certain activity to certain domains (subdirectories,  
> URL rewriting, etc.) I do not have other choice than using ‘if’ on the  
> $host variable leading to some complications due to the unreliable nature  
> of the ‘if’ clause.  
> The directory from which the content is served is determined by the  
> hostname.
> 
> On the other side, is using several servers to listen on several domains  
> the best solution?

Using separate per-domain server configuration blocks is both  
more efficient and easier to configure and maintain. Using a  
single server configuration block for many domains requires  
many “if” blocks, which are computationally intensive to  
evaluate, so you should avoid using them whenever possible.  
Most of the time you’ll be using “if” blocks for rewrites,  
so it’s better to just use separate server configuration  
blocks with direct rewrites.

Max

---

<div class="post-metadata">

**Author:** ![B.R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@B.R](https://www.ruby-forum.com/u/B.R)\
**Post date:** [February 9, 2012, 7:05pm UTC](https://www.ruby-forum.com/t/unique-server-for-all-domains-or-a-server-per-domain/216599/3 "2012-02-09T19:05:08Z")

</div>

OK, received loud and clear!

## Many thanks,

_B. R._
