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 this in my sites-available apache2 virtual host file:

 <VirtualHost *:80>

   ServerName  domain.com
   ServerAlias www.domain.com

...
</VirtualHost>

Why does apache send requests from www.domain.com to the correct path, but domain.com gets sent to the default virtual host?

Update: The reason domain.com gets sent to the default virtual host is because the hostname of the machine automatically gets sent to default.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

(Obvious question -- is the DNS for www and non-www the same?)

For debugging purposes the -S flag is useful to check the config as the apache service itself sees it.

Debian based world:

apache2 -S

Redhat based world:

httpd -S

and another example:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server localhost (/etc/apache2/sites-enabled/000-default:2)
         port 80 namevhost mydomain.com (/etc/apache2/sites-enabled/domain1:16)
         port 80 namevhost myotherdomain.com (/etc/apache2/sites-enabled/domain2:1
...etc
share|improve this answer

I'd check to see if you have the proper DNS records for domain.com and www.domain.com - where there is 1 main A record, and then a CNAME for the other.

You can do lookups with the tools at network-tools.com

share|improve this answer

Make sure you have DNS entries set for www to point to domain.com.

share|improve this answer

Is there a servername directive outside of the < virtualhost > section?

share|improve this answer

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.