How to List All Virtual Hosts in Apache Web Server

Channel: Apache Linux
Abstract: port 80 namevhost api.example.com (/etc/httpd/conf.d/api.example.com.confdefault server api.example.com (/etc/httpd/conf.d/api.example.com.conf

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.

Ref From: tecmint
Channels: Apache Tips

Related articles