Omid Kamangar
Omid Kamangar

Reputation: 5778

Named VirtualHost in apache overrides every other VirtualHosts

I have defined two VirtualHosts on Apache, and the problem is, one of them overrides the other one. i.e. when I try to reach the second address, the first one shows up.

Here is my first config:

ServerName www.example1.com
DocumentRoot /server/sites/example1

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /server/sites/example1
    ServerAlias example1.com
    <Directory /server/sites/example1/>
      AllowOverride All 
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

And the second:

ServerName www.example2.tv
DocumentRoot /server/sites/tv/public/

<VirtualHost *:80>
  ServerAdmin [email protected]
  DocumentRoot /server/sites/tv/public    
  <Directory /srver/sites/tv/public>
     # This relaxes Apache security settings.
     AllowOverride all 
     # MultiViews must be turned off.
     Options -MultiViews
  </Directory>
</VirtualHost>

When I load www.example2.tv, it still shows www.example1.com content.

example1 is written in PHP and example2 is Ruby on Rails.

Upvotes: 0

Views: 288

Answers (1)

arco444
arco444

Reputation: 22821

You need to have the ServerName directive inside the VirtualHost configuration i.e.:

<VirtualHost *:80>
  ServerName www.example2.tv
  ServerAdmin [email protected]
  DocumentRoot /server/sites/tv/public    
  <Directory /server/sites/tv/public>
     # This relaxes Apache security settings.
     AllowOverride all 
     # MultiViews must be turned off.
     Options -MultiViews
  </Directory>
</VirtualHost>

You can examine your configured VirtualHosts using apachectl -S - this will print a list of all the configured VirtualHosts and their corresponding config files

Upvotes: 1

Related Questions