Sunday, May 4, 2008

Named virtual hosts in Apache2

There's a common error that seems to happen fairly frequently which doesn't seem to have a whole lot of valuable solutions mentioned online. The error has to do with usage of the NameVirtualHost directive. It usually manifests itself with the following error message:
[warn] NameVirtualHost *:0 has no VirtualHosts

Searching the web leads to be plenty of discussion about how to possibly solve it, but not much truly relevant information. So if you find yourself staring at this error message, check for the existence of the following file:
/etc/apache2/conf.d/virtual
If it exists, it likely has the following contents, which tell the whole story:
#
# We're running multiple virtual hosts.
#
NameVirtualHost *


It is HERE where the NameVirtualHost directive is properly applied. Often times this file exists with this directive AND the /etc/apache2/sites-available/default file ALSO includes this directive. Under this condition, Apache will generate the warning message mentioned above.

So define it in conf.d/virtual and make sure it isn't in sites-available/default and you should be golden.