1

the Domain points to an IP / Server. But I like to have different documentRoots if the server is accessed via IP or via Domain. Therefore I build this configuration:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerAdmin foo@bar

  DocumentRoot /var/www/localhost
  <Directory /var/www/localhost>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory> 
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin foo@bar
  ServerName example.org
  ServerAlias example.org

  DocumentRoot /var/www/example.org
  <Directory /var/www/example.org>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>

</VirtualHost>

The problem is that accessing the IP or the domain will lead to the same page. What did I do wrong?

LeMike
  • 179
  • 1
  • 8

1 Answers1

1

Your config has one virtualhost with a servername of example.com, however the other virtualhost has no servername directive.

Lets say your ip is 10.0.0.1

You need to supply the servername of 10.0.0.1 for the virtualhost you want to respond to that ip.

Something like this:

<VirtualHost *:80>
  ServerAdmin foo@bar

  ServerName 10.0.0.1

  DocumentRoot /var/www/localhost
  <Directory /var/www/localhost>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory> 
</VirtualHost>
Drew Khoury
  • 4,569
  • 8
  • 26
  • 28