1

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 ?

4

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>
  • Ah, ServerAlias , of course :) – adrianTNT Jan 14 '12 at 16:16
2

You need the lines:

ServerAlias www.example.com

ServerAlias www.example2.com
2

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.

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.