How can I list the current Apache 2 virtual hosts from the command line?

36,019

Solution 1

The command a2query -s works perfectly for me.

Solution 2

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.

Solution 3

The apachectl -S documentation says this

-S Show the settings as parsed from the config file (currently only shows the virtualhost settings).

So you will only see those virtualhosts that are loaded in the config which is read when httpd starts.

Solution 4

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

Share:
36,019

Related videos on Youtube

lal kiran
Author by

lal kiran

Stackoverflow is my rubber duck.

Updated on September 18, 2022

Comments

  • lal kiran
    lal kiran over 1 year

    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.

  • Neo
    Neo almost 6 years
    This was the answer for me +1
  • blessed
    blessed over 2 years
    Thanks that worked for me. works the same to list modules and configurations: a2query [-m [MODULES] -s [SITE] -c [CONF] ]