How to List All Virtual Hosts in Apache Web Server

Apache virtual host configuration allows you to run multiple websites on the same server, that means you can run more than one website on the same Apache web server. You simply create a new virtual host configuration for each of your websites and restart the Apache configuration to start serving the website.

On Debian/Ubuntu, the recent version of Apache configuration files for all virtual hosts are stored in the /etc/apache2/sites-available/ directory. So, it makes really difficult to go through all of these virtual host configuration files to fix any configuration errors.

To make things easier, in this article we will show you how to list all enabled apache virtual hosts on a web server using a single command on the terminal. This method will also help you to see a few other useful apache configurations.

This is practically helpful in a scenario where you are assisting a company to fix their web server issues remotely, yet you do not know their current apache web server configurations, in regards to virtual hosts.

Read Also: How to Check Which Apache Modules are Enabled/Loaded in Linux

It will help ease searching for the virtual host of a specific website in the apache config files and assist in troubleshooting any apache issues, where you’ll, in most cases start with checking of the currently enabled virtual hosts before looking into the logs.

To list all enabled virtual hosts on the web server, run the following command in a terminal.

# apache2ctl -S   [On Debian/Ubuntu]
# apachectl -S    [On CentOS/RHEL]
OR
# httpd -S

You will get a list of all configured virtual hosts as well as another important apache/httpd server configurations.

List Apache Virtual Host Configurations
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
         port 80 namevhost tecmint.lan (/etc/httpd/conf.d/tecmint.lan.conf:1)
                 alias www.tecmint.lan
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex default: dir="/run/httpd/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: _RH_HAS_HTTPPROTOCOLOPTIONS
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48 not_used
Group: name="apache" id=48 not_used

From the above output, we can clearly see which ports and IP addresses are configured for each website. We will also see each website virtual host configuration file and their location.

This comes very helpful, when you are troubleshooting or fixing any apache virtual host configuration errors or you simply want to see a list of all enabled virtual host summary on a web server.

That’s all! You might also find these following related articles on Apache web server.

  1. 3 Ways to Check Apache Server Status and Uptime in Linux
  2. 13 Apache Web Server Security and Hardening Tips
  3. How to Change Default Apache ‘DocumentRoot’ Directory in Linux
  4. How to Hide Apache Version Number and Other Sensitive Info

If you have any questions relating to Apache HTTP server, use the comment form below to reach us.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.