Short Tip: Check configured virtual hosts in Apache

920839987_135ba34fff
Whenever you have to debug virtual host setups in Apache, checking the actual running virtual host configuration is a good first step. This can be done with the -S option used on the Apache binary: It lists all running virtual hosts and performs a syntax check.

On Fedora, RHEL, CentOS the Apache binary can be found on /usr/sbin/httpd:

# /usr/sbin/httpd -S
VirtualHost configuration:                                                        
1.2.3.4:80      me.example.net (/etc/httpd/conf.d/me.conf:5)
2.3.4.5:80      others.example.net (/etc/httpd/conf.d/others.conf:1)
2.3.4.5:443     others.example.net (/etc/httpd/conf.d/others.conf:38)
Syntax OK

On Debian systems the call is almost the same, you just have to source the environment variables upfront, and the binary has a different name for historical reasons:

# source /etc/apache2/envvars
# /usr/sbin/apache2 -S
VirtualHost configuration:                                                        
1.2.3.4:80      me.example.net (/etc/apache2/sites-enabled/me.conf:5)
2.3.4.5:80      others.example.net (/etc/apache2/sites-enabled/others.conf:1)
2.3.4.5:443     others.example.net (/etc/apache2/sites-enabled/others.conf:38)
Syntax OK

you might run into an error about user names, in such cases it is helpful to call upfront.

6 thoughts on “Short Tip: Check configured virtual hosts in Apache”

  1. I still somebody “here”?
    I have an issue with my virtual hosts:
    if I activate this statment in my httpd.conf

    Include conf/extra/httpd-fresas.conf

    where httpd-fresas.conf has this:

    ServerAdmin webmaster@fresas.com
    DocumentRoot “/xampp/htdocs/fresas”
    ServerName fresas.com
    ServerAlias http://www.fresas.com
    ErrorLog “logs/fresas.com-error_log”
    CustomLog “logs/fresas.com-access_logdocs” combined

    the server does not start

    but I add these same statments directly in the conf/extra/httpd-vhosts.conf
    the server start fine!
    why am i having this issue?

    I was originaly thinking in a statment like this:
    IncludeOptional conf/sites/*.conf
    to put all my virtual host configurations in the conf/sites directory,
    to have a more easy administration of them, but…

    1. Hi Juan,
      thanks for reaching out. But it is hard to help in a blog post comment section. How about you post the issue in unix.stackexchange.com or similar and see if you can get help there? You can also post the link to the issue here and I am happy to help in a forum where it is way easier to troubleshoot something.
      In general I would first check out the logs: they might directly tell you what is going on. If they don’t, post them as part of your issue as well.
      Hope that helps!

    2. Juan,

      See http://httpd.apache.org/docs/current/mod/core.html#serveralias :

      The value of the ServerAlias directive is supposed to be a list of host names inclusive-or domain names, not URIs, in this case URLs. In this case, the value of the ServerAlias directive should be “www.fresas.com” instead of “http://www.fresas.com”. URIs include both URNs and URLs, not only URLs. I follow the practice of Tim Berners-Lee (TimBL), the creator of the World Wide Web, to use the more general term “URI” unless it is necessary to distinguish between the two specific types of URIs but the common/popular usage is to use the specific term “URL”.

      Brolin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: