Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Apache and I have a CNAME DNS record for that points to

And I have an A DNS record for that points to the IP.

Then in my httpd.conf file I have:

<VirtualHost *:80>
        DocumentRoot /domain1/www

<VirtualHost *:80>
        DocumentRoot /domain1/sub1/www

Yet I appear to be missing something, as when you visit, it shows you the page for When you visit the, it shows the correct page for sub1.

share|improve this question
up vote 4 down vote accepted

Though you have CNAME record to point to the correct server, apache server maybe serving multiple website.

When a http request come in, apache check the URL against ServerName to determine which website to serve out. Should there be any additional name pointing to the same website, you put them in ServerAlias.

In your httpd.conf, you have to add ServerAlias for

<VirtualHost *:80>
    DocumentRoot /domain1/sub1/www

Additionally, the first VirtualHost declaration in httpd.conf is used as the default. When a http request comes in and doesn't match any ServerName and ServerAlias, the default site is serve out.

share|improve this answer
I was under the impression that when utilizing a CNAME record though, I wouldn't have to change any settings in apache. – mrc0der Nov 10 '12 at 3:08
Updated my answer to clarify. – John Siu Nov 10 '12 at 3:15
So will I be able to add 10,000 server alias's then? Google Apps lets you create CNAMES. For example that all point to; Essentially I'm going to be offering a service that will need to allow clients to setup CNAMEs and I will need to handle those requests. – mrc0der Nov 10 '12 at 3:21
So then, I dont need to do utilize ServerAlias, and just use the default VirtualHost declaration. – mrc0der Nov 10 '12 at 3:24
@mrc0der If they are going to the same website, you add them to ServerAlias of the corresponding VirtualHost section. If they are seperate website, you create new VirtualHost section for each of them. – John Siu Nov 10 '12 at 3:25

Your Answer


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.