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 currently have one main domain:

This is working fine.

What im trying to do is now adding a subdomain through my mydomain.conf file, so that I can have:

I've tried with the following - however the result of this is that im serving the content from at

<VirtualHost *:80>
ServerAlias *
DocumentRoot /var/www/

<VirtualHost *:80>
DocumentRoot /var/www/sub/html/

I've naturally created the DocumentRoot for the subdomain at: DocumentRoot /var/www/sub/html/

At my DNS-supplier, i've created an A-record for both: - and pointed it to my server IP. (the same IP that is pointing to)

Im running Centos 6.2.

Any ideas what is wrong here?

share|improve this question
up vote 3 down vote accepted

The problem is that your first VirtualHost has the line

ServerAlias *

This matches all subdomains. Since VirtualHosts are parsed in the order they appear in the config file, Apache will find this VH and never go on to look at the next one.

In other words, you will need to move the two domains around so that the VirtualHost entry for the subdomains apears above the one for the main domain.

share|improve this answer
By the way, if you're going to be using a lot of subdomains, you might be interested in using to simplify the configuration. – Jenny D Jan 9 '13 at 15:35
Hi Jenny - thanks a lot for the guidance. Your re-arranging trick did it for me. Ill surely also look into the url you posted. Appreciate the help! Thanks again – user1231561 Jan 9 '13 at 19:06
Your virtual host entry should be like this. Hope it will help you.

     ServerAlias *
     DocumentRoot /var/www/path_of_folder
share|improve this answer

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.