1

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):

apache2.conf:

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

ports.conf:

NameVirtualHost 123.123.123.123:80
Listen 80

/etc/apache2/sites-enabled/000-default:

<VirtualHost 123.123.123.123:80>
    DocumentRoot /home/landing/www
    <Directory /home/landing/www>
        Options None
        AllowOverride None
    </Directory>
</VirtualHost>

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

/etc/apache2/sites-enabled/domain1:

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

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

/opt/subdomain.conf:

<VirtualHost 123.123.123.123:80>
ServerName subdomain.domain1.com
DocumentRoot "/opt/subdomain/www"
</VirtualHost>

--> 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??

1
  • is /opt/subdomain.conf readable by the apache user? Jan 27, 2011 at 18:49

1 Answer 1

1

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

<VirtualHost 123.123.123.123:80>
    DocumentRoot /home/landing/www

to this

<VirtualHost _default_:80>
    DocumentRoot /home/landing/www
    ServerName blablabla
1
  • 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, 2011 at 20:41

You must log in to answer this question.