I want to to retrieve a list of the virtual hosts which are currently loaded and listening for requests i.e not just grepping the config files.
It looks like apache2ctl -S
does this but I am not 100% sure if that is just returning what is contained in the config files.
The command
a2query -s
works perfectly for me.The
apachectl -S
documentation says thisSo you will only see those virtualhosts that are loaded in the config which is read when httpd starts.
I didn't found official documentation about it.
The command
apache2ctl -S
check site-enabled*.conf + httpd.conf files and show you if the syntax is correct and the list of virtual host (and some more informations).But It doesn't check if virtualhosts are running, you can try to stop your Apache and launch again the command, the result will be the same.
So
apache2ctl -S
result is based on configuration files.You can use this command :
apache2ctl -t -D DUMP_VHOSTS
It will list all the enabled websites, the path to the conf file and the port that is used by the website
Will output the list of configured domains and aliases
Works fine on
Apache/2.4.38 (Debian)
Another approach can be to list all the link under the directory
/etc/apache2/sites-enabled
.This hold a link to each site currently enabled, and doesn't require root permission to list them.
A simple example taken from my home webserver:
The
sites-available
directory report other site apart from that: