I have been battling this weird problem for hours. I think I have all files in order and things should work, but they do not. I have

  • domain.com (alias: www.domain.com)
  • subdomain.domain.com

This should be two different websites.

These are my config files (Ubuntu 10.04):


Include /etc/apache2/sites-enabled/ 
Include /opt/subdomain.conf


Listen 80


    DocumentRoot /home/landing/www
    <Directory /home/landing/www>
        Options None
        AllowOverride None

--> NOT specitying a ServerName. Catches requests to the IP, and indeed opens /home/landing/www


    ServerName domain1.com
    DocumentRoot /home/domain1/www
    ServerAlias www.domain1.com
    <Directory /home/domain1/www>
    Options None +FollowSymLinks
        Order Allow,Deny
        Allow from All

--> This is for the main site. Opens fine, also with www.domain.com


ServerName subdomain.domain1.com
DocumentRoot "/opt/subdomain/www"

--> Here is the problem. This does NOT open. It opens /home/landing/www instead...? This happens when I open ANY subdomain, so this whole config appears ignored. Anybody any idea why? Or how to check??

  • is /opt/subdomain.conf readable by the apache user? – Kenny Rasschaert Jan 27 '11 at 18:49

As far as I can see this is due to not using ServerName in your first VirtualHost.

You can't mix up name and non-named based Virtual Hosting in apache, it confuses the hell out of it, apache will do the "best effort" to match a domain, following the configuration order.

The recommended way to make a default virtualhost is still to have a ServerName in it (as it should be) but change the VirtualHost line from

    DocumentRoot /home/landing/www

to this

<VirtualHost _default_:80>
    DocumentRoot /home/landing/www
    ServerName blablabla
  • Thanks! This did the trick. But I did NOT put a ServerName for default. Because this is supposed to be the 'catch-all' for any request for a site not configured, right? (say I type the IP instead of a site, then this should handle it?). So then I do not see what I should put for servername. And although my problem is now fixed, in fact when I put my IP I am being forwarded to /home/domain1/www, so still quite odd. But the problem is fixed. I will try to learn more about the deafult domain... Thanks for your help! – user60129 Jan 27 '11 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy