Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm interested in running a reverse proxy with 2-3 virtual machines behind it. Each internal server will run multiple virtual hosts, and rather than manually configuring each individual vhost on the proxy (a variety of vhosts come and go too often for this to be practical), I would like to use something which can employ pattern matching in a sequential order to find the appropriate back-end server. For example:

Server 1: *
Server 2: *
Server 3: *,,,
Server 4: *

In the above configuration, would go to Server 1, would go to Server 3, to Server 2, to Server 3, and to Server 4.

I've looked into using Squid, Varnish, and nginx so far. I have my opinions regarding their respective desirability and general suitability, but it's not readily apparent if any of them can handle dynamic server selection in this manner and not require per-vhost configuration. Apache on the other hand can do this handily and simply, but otherwise (aside from being well-known and familiar) seems very poorly suited to the partly-performance-serving task.

Performance isn't actually a major concern yet, but it seems foolish to use Apache if another system will perform far better and can also handle the desired 'hands-free' configuration. But so is frequently having to adjust the gateway for all production services and risk network-wide outage...and so also is setting oneself up for longer downtime later if Apache becomes a too-small bottleneck.

Which of these (or other) reverse proxies can do it/would do it best?

And maybe I should post this as a separate question, but if Apache is the only practical option, how safe/reliable/predictable is apache-mpm-event in apache2.2 (Ubuntu 12.04.1) particularly for a dedicated reverse proxy? As I understand it the Event MPM was declared "safe" as of 2.4 but it's unclear whether reaching stability in 2.4 has any implications for the older (2.2) versions available in official/stable package channels of various distros.

share|improve this question
I'm still digging for how to do this in Varnish, and already this question is topping the search results. :P – HonoredMule Sep 29 '12 at 1:17
up vote 0 down vote accepted

Varnish can definitely do this, if it's what you want to do.

You define your backends in your vcl file, and then in vcl_recv you can use a few regexes like so:

if (req.http.Host ~ "\.dev\.mysite\.com$") {
  set req.backend = server1;
elsif (req.http.Host ~ "\.stage\.mysite\.com$") { 
  set req.backend = server2;
elsif ...

I wouldn't personally recommend using the same varnish server for staging and production, I'd at least run a separate instance on another port, but that's neither here nor there.

share|improve this answer
Outside this consideration Varnish is my preference, so you could provide a little more detail or directions to the documentation that would cover this scenario, I'll award this as the answer. – HonoredMule Sep 29 '12 at 1:10
sure, why not.. – Pax Sep 29 '12 at 1:45
Recommendation noted...I'm actually running a very tiny operation and other forms of infrastructure segregation took higher precedence (like ips for DNS). :) There's one final part: what if "Server 4" isn't one server and I need to instead assign requests to a pool of servers? With further digging I was able to verify that I can use this same method and assign a Director to req.backend. Finally, I'll note the documentation for Varnish is actually quite good and I just wasn't quite putting the pieces together.… – HonoredMule Sep 29 '12 at 21:08

Personally, I use Pound. I would go into more detail but this question will be closed soon as its a shopping question.

I reworked most of my front end servers to go through a few Pound reverse proxies, which has let me cut my SSL certificate cost and IP usage greatly.

I have had them running for around 9 months now without a single problem so I can vouch for the reliability.

You can also do wildcard matching in the setup in the exact manner you want:

 HeadRequire "Host: .**"
 HeadDeny    "Host: .**"
share|improve this answer
Perhaps I should reword it as a howto not specific to the software used? My objective/question after all is to implement a specific administrative process and choice of software is only involved in so far as being a portion of my knowledge gap. At any rate thank you for the helpful answer. Pound looks like a possible solution, though I would rather have a caching proxy. – HonoredMule Sep 29 '12 at 1:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.