Apache virtual hosts allow you to run multiple websites on a single server, just by creating a separate virtual host configuration file for each separate website that you want to host on your server, and then restarting Apache web server. Generally, all virtual host configuration files are stored at /etc/apache2/sites-available directory. But you may not know which of these are enabled and which ones are disabled. Also it is time consuming to go through each configuration file to understand which sites they support. So in this article, we will learn how to list all virtual hosts in Apache web server. This is useful especially if you are managing multiple websites in one server and need to fix issues arising in any of them. If you are a new system administrator, it is also useful in finding out which all websites are being served by your Apache installation. It is also useful in searching the virtual host configuration of a specific website in config file and do troubleshooting.
How to List All Virtual Hosts in Apache
To list all enabled virtual hosts on your server, open terminal and run the following command.
# apache2ctl -S [On Debian/Ubuntu] # apachectl -S [On CentOS/RHEL] OR # httpd -S
The above command will show a list of all domains (virtual hosts) enabled on your server, and other important information.
VirtualHost configuration: *:80 is a NameVirtualHost default server api.example.com (/etc/httpd/conf.d/api.example.com.conf:1) port 80 namevhost api.example.com (/etc/httpd/conf.d/api.example.com.conf:1) alias www.api.example.com port 80 namevhost corp.example.com (/etc/httpd/conf.d/corp.example.com.conf:1) alias www.corp.example.com port 80 namevhost admin.example.com (/etc/httpd/conf.d/admin.example.com.conf:1) alias www.admin.example.com ...
The above output clearly shows the IP address and port number configured for each website. We also see the website virtual host configuration file and their location.
This is useful when you have multiple websites running on your server and want to quickly find out the location of specific website or all websites for debugging.
Once you know the location of virtual host file, or even know which virtual host configuration file is meant for which website, you can easily edit it as per your requirements. Otherwise, you may end up changing the wrong file and affecting the wrong website. Many new webmasters and system administrators have this requirement and the above steps should help you easily get a list of all virtual hosts enabled on your server, which domains they support, their file locations, and IP addresses with port numbers.
How to Create Virtual Hard Disk Volume from File in Linux
How to Downgrade Software in Ubuntu
How to Downgrade RHEL/CentOS to Previous Minor Release
How to Mount Windows Partition in Ubuntu
Top Hex Editors in Linux