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.

On Cent OS 6, apache 2.2, Bind 9.7.3 I cannot get my domains to load with www cname. If I type example.com it loads fine, but www.example.com loads my main apache directory from /var/www/html

This is what I have in httpd.conf:

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot "/var/www/html/_domains/example.com"
ServerName example.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/html/_domains/example2.com"
ServerName example2.com
</VirtualHost>


<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName 94.00.00.00
</VirtualHost>

And a zone file for example.com looks like this:

$ttl 38400
example.com.    IN  SOA example.com. webmaster.example.com. (
            1326544028
            10800
            3600
            604800
            38400 )

example.com.          IN NS   ns1.example.com.
example.com.          IN NS   ns2.example.com.
ns1.example.com.               IN A    94.00.00.00
ns2.example.com.               IN A    94.00.00.00
example.com.          IN A    94.00.00.00
mail.example.com.             IN A    94.00.00.00
www.example.com.              IN CNAME        example.com.
example.com.          IN MX  10 mail.example.com.

Any thoughts on why www.example.com would load the default html directory /var/www/html instead of /var/www/html/_domains/example.com ?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

That's because you are not including www into your Virtualhost. So Apache does not know what you are talking about. So you need to add a ServerAlias as well :

<VirtualHost *:80>
   DocumentRoot "/var/www/html/_domains/example.com"
   ServerName example.com
   ServerAlias *.example.com
</VirtualHost>
share|improve this answer
    
Ah, ServerAlias , of course :) –  adrianTNT Jan 14 '12 at 16:16

You need the lines:

ServerAlias www.example.com

ServerAlias www.example2.com
share|improve this answer

It seems that you need to the ServerAlias directive. So, your virutal host defintion should look like:

<VirtualHost *:80>
DocumentRoot "/var/www/html/_domains/example.com"
ServerName www.example.com
ServerAlias example.com *.example.com
</VirtualHost>

For more info, you can see.

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.