As I often get involved in server administration (SVN, git, redmine, etc setup), I deal with Apache on a regular basis. For simple configurations, the default Ubuntu/debian config works well. However, for a more complex setup with virtual hosts, multiple IP addresses, and SSL support, it is common to run into the following message:
mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
Googling does not return a clear explanation to this problem, so that is why I’m writing this article. The impulsive approach of randomly changing things does not get you too far — especially with the Debian/Ubuntu Apache configuration that is composed of seperate files for each virtual host. After reading the documentation, things become clearer:
Note that the argument to the
<VirtualHost> directive must exactly match the argument to the
And, by considering the fact that the seperate virtual host config files really just get concatenated into one big file, it makes sense that you can’t have more than one NameVirtualHost entry. Ubuntu by default puts the NameVirtualHost in the default virtual host file, which gets soft linked to sites-enabled/000-default. I presume the ‘000’ means it gets loaded first. I find it much more intuitive to put the NameVitualHost directives in the /etc/apache2/httpd.conf file. This way it is clear that these entries are common to all virtual host entries. So what I end up with is:
NameVirtualHost 126.96.36.199:80 NameVirtualHost 188.8.131.52:80 NameVirtualHost 184.108.40.206:443
<VirtualHost 220.127.116.11:80> ServerName bec-systems.com ...
<VirtualHost 18.104.22.168:443> ServerName bec-systems.com ...
<VirtualHost 22.214.171.124:80> ServerName svn.bec-systems.com ...
/etc/apach2/sites-available/site2.com (with different IP address)
<VirtualHost 126.96.36.199:80> ServerName site2.com ...
Again, the points to remember are:
- The argument to VirtualHost must match a NameVirtualHost directive
- the NameVirtualHost directive is common, so there should only be one entry
Thank you so much for this simple example. This particular issue has been bugging me for quite some time.
Big thanx for that simple exemple, it helped me very much !!!!
Thanx a lot for this man!
I’m confused. First you seem to say that you have three “entries” for NameVirtualHost in your httpd.conf
Then at the end your second point to remember is that there should only be one entry.
Let me clarify–there should only be one NameVirtualHost per IP address and port combination. Notice in the above list, there are three separate IP address/port combinations. It is often common to bind multiple sites to a single IP address, which is where you run into this issue. For example, svn.bec-systems.com, git.bec-systems.com, http://www.bec-systems.com all resolve to a single IP.
It appears that the with Ubuntu 10.04, the standard place to put the NameVirtualHost statements is in /etc/apache2/ports.conf
Whenever I read through the Apache docs, my eyes go into a spiral and I’m unable to grok things that are there. If only they were as well written as this. Your post helped me to get two additional IP addresses working on our server, but more importantly to understand the NameVirtualHost directive. Thanks.
Thanks! This helped a bunch.
To sumarize what I did, just to make it easier for others coming here later, I added
in files in /etc/apache2/sites-available/
and made sure
was there too.