I spent the evening rebuilding a web server that will be running Apache 2.0.x. While doing so, I found an interesting situation with respect to the standard Apache configuration on Ubuntu 5.04. The standard configuration uses a namevirtualhost directive to set up multiple virtual servers on the machine. This is normal. The problem is that when Apache reads the default website configuration, it does a DNS lookup, and finds the host’s fully qualified domain name (FQDN). After that, any virtual host directives that try to use that name as the ServerName just don’t work. Worse, they fail silently!!! This is not good, because they cause the box to send the ugly default Apache page instead of my beautifully hand-crafted html.
The easy workaround is to put a ServerName directive into the default site setup which goes to nowhere in particular (I used nowhere.jricher.com). This avoids the reverse DNS lookup, and then the virtualhost section for the server’s hostname works just fine.
What is really annoying is that I couldn’t find a decent article on debugging Apache virtual host setups. If there had been a single one-liner in the Apache virtual host docs which mentioned the use of apache2ctl -S I would probably have saved myself several hours of trouble.
Note for the unwise:
apachectl (apache2ctl on Ubuntu, Debian, and some others) can be convinced to dump the virtual host setup for the box by using the “-S” option. It’s not documented anywhere. I got the command option from a guy on IRC who was helping me debug this mess. Remember, for apache virtual host trouble use “apachectl -S”. End sermon…