Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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>
share|improve this answer
    
That was obvious but I didn't saw it. Thanks so much! Works like a charm. –  Mike Pretzlaw Aug 28 '13 at 5:23

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.