I have a fresh minimal Debian Lenny server with one IP address running just Apache.

I have two domains, site1.com and site2.com for the purpose of this post, pointing to this one server. The www subdomain is a CNAME to the main domain. Pinging all four entries (the two domains with and without the www subdomain) all point to the correct IP address.

On the server, two virtual hosts have been added to /etc/apache2/sites-available/ as follows:

<VirtualHost *:80>
    ServerName www.site1.com
    ServerAlias site1.com
    DocumentRoot /var/www.site1.com
    <Directory /var/www.site1.com/>
            Options FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all
    ErrorLog /var/log/apache2/www.site1.com-error.log
    LogLevel warn
    CustomLog /var/log/apache2/www.site1.com-access.log combined

The second is just a copy of the above but with site2 references.

Having enabled both virtual hosts, and restarting Apache, site1.com, site2.com and www.site2.com all point to their correct sites. However for some annoying reason www.site1.com points to the default site (/etc/apache2/sites-available/default) for non-matching virtual hosts.

Can anyone explain why this is happening? I've checked and re-checked the configs, logs, directories and even re-built the server cleanly numerous times and fail to understand Apache's behaviour in this example.

Your help is appreciated.


I'm going with typo in the vhost's ServerName, or else the machine's ServerName points to www.site1.com and that's overriding the vhost's definition.

  • Checked the vhost's ServerName entry numerous times now. Even copy and pasted it in all cases to be sure. No difference. When you say the machine's ServerName, where should I be looking exactly? Could it be related to the reverse DNS being the very same address I can't get working? – Asinine Monkey Nov 10 '09 at 17:08
  • Yes, that's exactly what I mean. – womble Nov 10 '09 at 17:14
  • Hmm, never actually thought of that. Will alter it and re-test. – Asinine Monkey Nov 10 '09 at 17:29
  • How annoying. That solved it first time. Lesson learnt I guess. Many thanks. :) – Asinine Monkey Nov 10 '09 at 17:37

I know it might be a late response .. but maybe you should check if you have the NameVirtualHost Directive Set up .. if you have too many Virtual Hosts with it set, Apache will override to either the last one in the list .. or give you an error and not start the service at all ..

  • This is misleading. There are some strange behaviors when mixing NameVirtualHost and other vhost configurations, but not ever because there are "too many". – Jeff Warnica Dec 8 '12 at 22:33

Your Answer

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

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