Get a list of all virtual hosts which are defined in all apache configuration files
Have you ever searched where the virtual host of a website is defined in the apache config files? There is a handy option of the apache2ctl script which might help then. When you run the command:
apache2ctl -S
on the shell, you will get a list of all virtual hosts and default servers incl. the line number where it is defined. 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 tipp.
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.