Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
4  
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
add comment

1 Answer

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>

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

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
add comment

Your Answer

 
discard

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.