Get a list of all virtual hosts which are defined in all apache configuration files

Have you ever looked in the apache config files to see where a website's virtual host is defined? The apache2ctl script has a useful option that could come in good here. When you execute the command, it should look like this:

apache2ctl -S

You'll obtain a list of all virtual hosts and default servers in the shell, along with the line number where they're declared. Example:

~# apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:8080                 is a NameVirtualHost
default server ispconfig.local (/etc/apache2/sites-enabled/000-ispconfig.vhost:10)
port 8080 namevhost ispconfig.local (/etc/apache2/sites-enabled/000-ispconfig.vhost:10)
*:8081                 is a NameVirtualHost
default server ispconfig.local (/etc/apache2/sites-enabled/000-apps.vhost:10)
port 8081 namevhost ispconfig.local (/etc/apache2/sites-enabled/000-apps.vhost:10)
*:80                   is a NameVirtualHost
default server ispconfig.local (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost ispconfig.local (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com.vhost:7)
Syntax OK

Thanks to Planetfox for this tip.

Till Brehm

View Comments

  • If only you could pipe the output from httpd -S. It's unpipable :(
    "httpd -S | grep something" would be soooo useful when running a ton of sites but the output just goes to console anyway.

  • Charles,

    It's using standard error, instead of standard out. You can redirect standard error as follows:

    apachectl -S 2> allhosts.txt

    Then you can grep or whatever you need to do with allhosts.txt

    Regards,
    -Eric ;.,

  • Or if you want to pipe it you can redirect stderr to stdout.

    apachectl -S 2>&1 | grep something

    It saves the step of sending the output to a file.

  • apache2ctl -S | grep namevhost | awk -F ' ' '{ print $4 }'

    should list all domains (tested on ubuntu 14.04-trusty)

Recent Posts

How to Remove Directories in Linux

Spring cleaning is not only necessary for homes, Your Linux Mint 20 file system also…

2 days ago

How to disable Thumbnails for Files in Windows 10

Even in this day and age of high-speed PCs, many people use detachable or linked…

3 days ago

Restore old Clock, Calendar and Battery on the Windows 10 taskbar

Windows has significantly altered the user interfaces for the clock, calendar, and battery. While the…

4 days ago

Change the location of the Windows 10 update download folder

To upgrade your system to the most recent version, you must have enough storage space…

2 weeks ago

How to disable the Windows 10 Phone Linking feature

You may connect your Android or iPhone to your PC and use the function on…

2 weeks ago

Pin Folders to the Windows 10 Taskbar

You won't be able to directly add folders to the taskbar in Windows 10. In…

3 weeks ago