Apache Server Find Virtual Host Config Location

The virtual host configuration is a part of the Apache web server’s (HTTPD) main configuration file only. You either write the <VirtualHost> directive blocks right into the main server config file or you put it in a separate file and load that inside the main config using Include or IncludeOptional. The latter is much more common.

How do we find out the file locations that contain the virtual host configuration though ? It’s easy, we can use the apachectl or httpd command line tools to do that.

$ apachectl -D DUMP_VHOSTS
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server catchall (/etc/apache2/sites-enabled/000-catchall.conf:1)
         port 80 namevhost catchall (/etc/apache2/sites-enabled/000-catchall.conf:1)
         port 80 namevhost codingshower.com (/etc/apache2/sites-enabled/codingshower.conf:1)

The -D DUMP_VHOSTS option passed to apachectl or httpd will show all the parsed vhost or virtual host settings. This way you should be able to easily figure out where all your virtual host configurations for a particular IP-based or Name-based virtual host lives. In my case that is /etc/apache2/sites-enabled/codingshower.conf.

Let’s look at some other variations of the command above:

$ apachectl -t -D DUMP_VHOSTS
$ apachectl -S

# With httpd (same options)
$ httpd -D DUMP_VHOSTS
$ httpd -t -D DUMP_VHOSTS
$ httpd -S

Leave a Reply

Your email address will not be published. Required fields are marked *