Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Do you have options NameVirtualHost *:80 and Listen *:80 ? –  ALex_hha Feb 9 at 19:33

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
Adding ServerName localhost to the default virtual host seemed to solve the problem. What I don't understand is that it's been working fine with the config I posted for 2 days. All of a sudden overnight it stopped working. Apache2 wasn't even killed or reloaded. The vhosting just stopped working. Thanks for your help. –  cz3ch Feb 9 at 17:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.