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 a VPS running Apache 2.0, with multiple domains and multiple IPs set.

In document root /var/www/html/ I have http://serverA.com and I created a virtual host on folder /var/www/html/serverB serving http://serverB.com.

They work great for both, but the problem is I can access serverB files with URL 'http://serverA.com/serverB/' (which I don't want to happen.)

How can I prevent that?

share|improve this question
Make the ServerA files from /var/www/ServerA/ and ServerB files from /var/www/ServerB/ and use those paths as the DocumentRoot in the apache.conf file for each of those (in their VirtualHost block). – ionFish Jun 4 '12 at 1:45

You have to pay attention to two directives specially:

  1. ServerName
  2. DocumentRoot

Below is an example of two virtual hosts configured on top of the same IP:

<VirtualHost W.X.Y.Z:80>
  ServerName   serverA.com
  DocumentRoot "/var/www/html/serverA"
  # + other stuff like logging directives, etc.

<VirtualHost W.X.Y.Z:80>
  ServerName   serverB.com
  DocumentRoot "/var/www/html/serverB"
  # + other stuff like logging directives, etc.

As you can see both ServerName and DocumentRoot directives are specified and are different. With this kind of configuration you are sure that the two different domain names, "ServerA" and "ServerB", as well as the files they are serving, cannot collide.

The above configuration can easily be adapted for domain names with different IPs as long as you specify the ServerName and the DocumentRoot directives. You have to only change the VirtualHost IP.

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.