Load balancing multiple virtual hosts on 1 IP

Geoff Fritz gfritz at gmail.com
Sat Jan 31 15:11:33 PST 2009


On Sat, Jan 31, 2009 at 09:23:36AM -0400, Marc G. Fournier wrote:
> 
> Simple: is it possible?
> 
> I have two VMs that contain the same content, on two different IPs .. I 
> want to setup a third VM with something like haproxy on it that will take 
> the URL (http://domain1) and pull the content from one or the other ...
> 
> So far, all works well if I only have one virtual host, but as soon as I 
> add a second one (http://domain2), when I try to go to http://domain2, it 
> pulls up the content for domain1 also, as if I was going to http://IP 
> instead.
> 
> Is there a way to set this up (with haproxy, or some other software), that 
> it will actually pass the URL through to the backend apache server and 
> load up the right content?  Or is this a limitation in the protocol 
> itself?/

Sounds like your front end is messing up the request.  If the back end
servers get the correct domain in the host header, they should do the right
thing and return the data from that domain.

As for alterntatives...

I have used "pen" for simple load balancing of web servers, and it does
what you need.  Very minimal and simple.

Apparently, Slashdot uses "pound" for their load balancing, so it should do
the trick, too.

On the slightly more complex side, I've recently starting using "varnish"
to split work between Apache and nginx (all three running in the same jail,
thus all bound to the same IP address).  It is capable of doing what you
need, but it's main purpose is a reverse caching proxy, so a bit more care
would be needed if you don't actually want stuff cached.

All three (pen, pound, and varnish) are in ports.

-- Geoff


More information about the freebsd-questions mailing list