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 22.214.171.124:80 NameVirtualHost 126.96.36.199:80 NameVirtualHost 188.8.131.52:443
<VirtualHost 184.108.40.206:80> ServerName bec-systems.com ...
<VirtualHost 220.127.116.11:443> ServerName bec-systems.com ...
<VirtualHost 18.104.22.168:80> ServerName svn.bec-systems.com ...
/etc/apach2/sites-available/site2.com (with different IP address)
<VirtualHost 22.214.171.124: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