Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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've tried to use NamedVirtualHosts to setup a single server to handle two websites. This is the first time I've attempted this, and I'm getting very unusual behavior. Specifically, requests to point o /home/stefan/example2, but points to /home/stefan/example1.

Does anyone have any idea what's going on here?



NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot /home/stefan/example1

<VirtualHost *:80>
   DocumentRoot /home/stefan/example2
share|improve this question
up vote 3 down vote accepted

I am guessing that what you really meant to say was that goes to the right place, but goes to the site.

You need to use the "ServerAlias" directive and and insert the domain without the "www" in there.

Something like following in the appropriate section:



share|improve this answer
Exactly what I needed. Thanks! – Stefan Kendall Jul 6 '09 at 3:17
The explanation as to why you're seeing this problem is that and are considered different hosts by apache. You don't have a virtual host configuration for, so apache uses the default vhost, which is the first one configured, which in your case happens to be – David Pashley Jul 6 '09 at 7:37

What's the problem, sounds like it's working perfectly.

You have a vhost for going to the right place. Any hostnames that you don't have a vhost for (like will go to the first vhost.

share|improve this answer

From the Apache2 docs -

Due to the fact that is first in the configuration file, it has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by this first VirtualHost.

So, since you don't have a vhost defined for, Apache will use the default vhost. In your case, this is

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.