Webmasters Stack Exchange is a question and answer site for pro webmasters. 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 have these virtual hosts set up however when I browse to domain.com or they both point to /var/www/html/. How can I get them set up so they point to correct DocumentRoot?

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

<VirtualHost *:80>
  ServerName domain.com
  DocumentRoot /var/www/vhosts/domain.com/htdocs

EDIT: I actually had a seperate vhosts.conf file located in /etc/httpd/conf.d/. Subsequently this was being loaded (unbeknownst to me) by Include conf.d/*.conf before --

NameVirtualHost *:80
Listen 80

I have moved the vhosts out of that directory and into /etc/httpd/conf/vhosts/ and amended my Include file at the bottom of httpd.conf to --

Include /etc/httpd/conf/vhosts/*.conf

I have also tried uncommenting ServerName and defining it as my servers IP and removing the first VirtualHost.

The result of this is that domain.com points to the correct site though the IP points to that site now too.

share|improve this question
edited question – atb Aug 8 '12 at 22:07

Make sure these are in your Apache configuration BEFORE the VirtualHost containers:

NameVirtualHost *:80
Listen 80

The reason you see the same content on both URLs is because Apache uses the FIRST VirtualHost as the "default" so any hostname not matching a VirtualHost will automatically be served as the first one you have.

Please report back the results.

share|improve this answer
I have that config already: Listen 80 NameVirtualHost *:80 Include /etc/httpd/conf.d/vhosts.conf – atb Aug 7 '12 at 4:17
@allanb - Would you mind posting your entire config? (Paste it somewhere). – ionFish Aug 7 '12 at 4:27
pastebin.com/z6Hetmzv – atb Aug 7 '12 at 4:48
@allanb - I can't find anything technically wrong with your configuration. Though I probably missed something simple because it's very early in the morning and there are no lights in here, but maybe someone else could be of more help. – ionFish Aug 7 '12 at 5:17

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.