A couple of weeks ago I was trying to work out why a given Apache virtual host wasn’t serving the correct content. I knew which virtual hosts I’d defined and enabled (the
sites-enabled directories under
/etc/apache2 on Debian), but I couldn’t tell whether Apache was loading them correctly. After a bit of searching, I found that
apachectl -S will show all the virtual hosts, as well as some useful information such as the main error log file (you may be able to run the command as a non-root user, depending on how your server is configured). The output looks like this:
VirtualHost configuration: *:80 is a NameVirtualHost default server davros.xk7.net (/etc/apache2/sites-enabled/000-default.conf:1) port 80 namevhost currybeer.co.uk (/etc/apache2/sites-enabled/currybeer.co.uk.conf:1) port 80 namevhost www.currybeer.co.uk (/etc/apache2/sites-enabled/currybeer.co.uk.conf:7) ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/var/log/apache2/error.log" PidFile: "/var/run/apache2/apache2.pid"
In this example, I can see that the default server is
davros.xk7.net, and I also have a file defining two name-based virtual hosts,
www.currybeer.co.uk. The output even provides the line numbers for each file, which might be useful if you’re running a server which doesn’t use a sensible convention such as naming the file after the virtual hosts it defines.