WordPress – Apache2 Default overrides virtual host

apache-2.2domain-name-systemvirtualhostWordpress

I have an Ubuntu 12.10 LTS server running apache2 with a simple wordpress install. I created the virtual host in /etc/apache2/sites-available and used a2ensite to enable it. All was working fine for two days.

This morning I woke up to check the site and it seemed the virtual host was not working at all. It kept going to the default site in apache2.

Here is my config:

default

<VirtualHost *:80>
    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 ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    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>

virtual host: domain.com

<VirtualHost *:80>
     ServerAdmin me@domain.com
     ServerName domain.com
     ServerAlias www.domain.com
     DocumentRoot /srv/www/domain.com/public_html/
     ErrorLog /srv/www/domain.com/logs/error.log
     CustomLog /srv/www/domain.com/logs/access.log combined
</VirtualHost>

As you can see I have two separate configs with no conflicts. But apache2 keeps reverting to the default site instead of the name-based vhost. My /etc/hosts file is correct and has a FQDN and host name pointed to the public-facing IP as well. This just happened overnight.

I ran a a2dissite on domain.com, apache2 reload, then a2ensite on domain.com with no results. I ended up having to a2dissite the default config. Once I did that the domain.com site came up with my wordpress site just fine.

Any idea why this happened? I've ran apache2 and nginx for years and have never had a problem with virtual hosting. This one is a bit weird. I shouldn't have to disable the default site for my other virtual host to work.

Any thoughts?

Best Answer

Try adding

ServerName localhost

into the default virtual host. Also you could temporarily disable the < Directory / > section from the default virtual host, it seems to be useless.