Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a situation where I have a load balancer set up with Apache2 and mod-balancer that is going to load balance two Apache2 web servers. I'd like my load balancer to be able to serve multiple sites but currently every virtual host I create seems to serve the same site.

On the load balancer (lb1) I have the default virtual host enabled so that when you browse to the load balancers IP address you see the standard Apache2 message.

The following is the virtual host layout that I use for all subsequent domains that the load balancer can serve (substitute mydomain.com for the actual domain name of course):

<VirtualHost *>
        ServerName www.mydomain.com
        ServerAlias mydomain.com

        ProxyRequests Off

        <Proxy *>
                Order deny,allow
                Allow from all

        <Proxy balancer://mydomain.com.cluster>
                BalancerMember http://web1.mycluster.com:80 route=web1 retry=5
                BalancerMember http://web2.mycluster.com:80 route=web2 retry=5
                ProxySet lbmethod=byrequests

        ProxyPass / balancer://mydomain.com.cluster/ stickysession=BALANCEID n$

        ProxyPassReverse / http://web1.mycluster.com/
        ProxyPassReverse / http://web2.mycluster.com/

This is what a virtual host on the web server (web1 & web2) end looks like. Both web servers have the same virtual hosts enabled. The only difference between the virtual hosts is the reference to either web1 or web2 respectively (I show the virtual host of web1 here):

<VirtualHost *>
        ServerName www.mydomain.com
        ServerAlias mydomain.com

        RewriteEngine On
        RewriteRule .* - [CO=BALANCEID:balancer.web1:.mydomain.com]

        DocumentRoot /mnt/share/mydomain.com/www/public_html

        <Directory />
                Order allow,deny
                Allow from all

This seems to work for mydomain.com. If I create another virtual host with the same layout e.g. for myotherdomain.com then browsing to myotherdomain.com will actually serve mydomain.com.

What I'm I doing wrong?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You probably need a NameVirtualHost directive somewhere, otherwise requests are matched by the server IP address only and the first VirtualHost that matches this IP will 'win' (so the first always wins).

At least, it worked that way years ago, when I had more to do with Apache.

share|improve this answer

Jaccek Konieczny was right and I finally found out what the issue was. I'd like to elaborate on it a bit. It appears that it had to do with how I configured my virtual hosts and it was always picking the default one on either one of the load balanced servers. This is how I end up setting my virtual hosts:

For the default vhost:

NameVirtualHost *:80
<VirtualHost *:80>

  # vhost stuff


Then for the other virtual hosts:

<VirtualHost *:80>
  ServerName mydomain.com
  ServerAlias www.mydomain.com

  # forward proxy stuff


All the web server nodes are configured as they would have been standalone machines except for the BALANCEID cookie being set.

share|improve this answer

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.