Show all Apache virtual host definitions

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-available and 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 (/etc/apache2/sites-enabled/000-default.conf:1)
 port 80 namevhost (/etc/apache2/sites-enabled/
 port 80 namevhost (/etc/apache2/sites-enabled/
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
PidFile: "/var/run/apache2/"

In this example, I can see that the default server is, and I also have a file defining two name-based virtual hosts, and 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.


No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.