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

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
    </Directory>
    ErrorLog /var/log/apache2/www.site1.com-error.log
    LogLevel warn
    CustomLog /var/log/apache2/www.site1.com-access.log combined
</VirtualHost>

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
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 ..

share|improve this answer
    
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

 
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.