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.

8 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

  2. Thank you very much for your support!
    It seems that I just had one directory missing!! (I create it with a misspelling) after I fixed that all is working fine now! (Brolin, the ServerAlias was ok, but the process “here” changed it to include the http://…).
    is there a way to say “solved” and then close it?
    Also I’m sorry for my delay to answer you, I was working in other stuff!

    1. Hi Juan, thanks for letting us know that this helped. That is really nice, even after such a long time!
      Glad that it is now solved, others will realize that by reading the comments.

Leave a comment

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