4

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?

1
  • 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, 2012 at 1:45

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.