151

Once again, I have a problem with my apache virtual host configuration. (The default configuration is used instead of my specific one).

The problem is not really the misconfiguration but how to solve it.

Does anyone has good advices to do resolve this kind of problem quickly?

Some more informations.

The default conf file is this one:

NameVirtualHost *
<VirtualHost *>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

And the virtual host config that doesn't apply is this one:

<VirtualHost *:*>

ProxyPreserveHost On
ProxyPass / http://ip.ip.ip.ip:8088/
ProxyPassReverse / http://ip.ip.ip.ip:8088/
ServerName wiki.mydomain.com

</VirtualHost>
GaetanZ
  • 2,819
  • 3
  • 21
  • 20
  • DNS checks are also useful e.g. flushdns https://coolestguidesontheplanet.com/clear-the-local-dns-cache-in-osx/ https://www.hostinger.com/tutorials/how-to-flush-dns – Wolfgang Fahl Sep 28 '20 at 13:28

8 Answers8

220

Syntax check

To check configuration files for syntax errors:

# Red Hat-based (Fedora, CentOS), Arch-based and OSX
httpd -t

# Debian-based (Ubuntu)
apache2ctl -t

# MacOS
apachectl -t

List virtual hosts

To list all virtual hosts, and their locations:

# Red Hat-based (Fedora, CentOS), Arch-based and OSX
httpd -S

# Debian-based (Ubuntu)
apache2ctl -S

# MacOS
apachectl -S
Stefan Teunissen
  • 402
  • 6
  • 19
sqren
  • 22,833
  • 7
  • 52
  • 36
  • 5
    `-S` is a synonym for `-t -D DUMP_VHOSTS` so those two are the same – aron.duby Jan 20 '15 at 19:40
  • 3
    For Windows, (if you are using xampp), you have these same commands at: \xampp\apache\bin – James John McGuire 'Jahmic' Dec 06 '15 at 10:38
  • For Wamp: `c:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -S` – Lg102 Dec 28 '15 at 10:05
  • 4
    That's very useful, thank you but it is not enough, I got some trouble with a vhost that it should be used and is not, i dont know why, I wish to get logs about how apache choose the vhost. – Loenix Nov 12 '16 at 09:35
  • 1
    Is there any way to make Apache add a message to the error file or elsewhere when an actual access comes in for a virtual or main host giving dynamic information about which host was chosen? I have tried LoadModule log_debug_module modules/mod_log_debug.so ... LogMessage "Debug 1" hook=all – David Spector Nov 16 '17 at 19:01
  • windows found this (on git basch console): ./httpd.exe -S – Rubén Ruíz May 13 '21 at 22:17
33

Here's a command I think could be of some help :

apachectl -t -D DUMP_VHOSTS

You'll get a list of all the vhosts, you'll know which one is the default one and you'll make sure that your syntax is correct (same as apachectl configtest suggested by yojimbo87).

You'll also know where each vhost is declared. It can be handy if your config files are a mess. ;)

KatieK
  • 13,586
  • 17
  • 76
  • 90
Arnaud Massé
  • 596
  • 6
  • 3
28

If you are trying to debug your virtual host configuration, you may find the Apache -S command line switch useful. That is, type the following command:

httpd -S

This command will dump out a description of how Apache parsed the configuration file. Careful examination of the IP addresses and server names may help uncover configuration mistakes. (See the docs for the httpd program for other command line options).

Michael Spector
  • 36,723
  • 6
  • 60
  • 88
17

First check out config files for syntax errors with apachectl configtest and then look into apache error logs.

yojimbo87
  • 65,684
  • 25
  • 123
  • 131
15

I had a new VirtualHost configuration file that was not showing when using the apachectl -S command. After much head scratching I realised that my file did not have suffix ".conf". Once I renamed the file with that suffix my Vhost started showing and working!

GreensterRox
  • 6,432
  • 2
  • 27
  • 30
10

I recently had some issues with a VirtualHost. I used a2ensite to enable a host but before running a restart (which would kill the server on fail) I ran

apache2ctl -S

Which gives you some info about what's going on with your virtual hosts. It's not perfect, but it helps.

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
5

I found my own mistake, I did not add log file name: ErrorLog /var/log/apache2
And this path: Directory "/usr/share/doc/" Did not contain website sources.

After I changed these two, all worked. Interestingly, apache did not issue any errors, just did not open my website silently on my Mac OS Sierra.

Konstantin Vahrushev
  • 1,110
  • 2
  • 11
  • 20
  • Good answer, help me find similar issue. All syntax and -S vhosts correct, still wrong site served. Turned out to be :80 and :443 has the same access log file, which seemed to confuse things. Separate file for each port, and sites started working. – David McNeill May 10 '20 at 09:48
1

a very important tool is

apachectl -t -D DUMP_INCLUDES

it showed me that the file that i was fixing and mending was in fact included by a file that was itself not included.

thank everybody

alex
  • 651
  • 1
  • 9
  • 11