在apache中命名为VirtualHost会覆盖其他所有VirtualHost

时间:2014-01-13 09:34:53

标签: apache virtualhost

我在Apache上定义了两个VirtualHosts,问题是,其中一个覆盖了另一个。即当我试图到达第二个地址时,第一个地址出现。

这是我的第一个配置:

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

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

第二个:

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

<VirtualHost *:80>
  ServerAdmin admin@example2.tv
  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>

当我加载www.example2.tv时,它仍会显示www.example1.com个内容。

example1是用PHP编写的,example2是Ruby on Rails。

1 个答案:

答案 0 :(得分:1)

您需要在VirtualHost配置中包含ServerName指令,即:。

<VirtualHost *:80>
  ServerName www.example2.tv
  ServerAdmin admin@example2.tv
  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>

您可以使用apachectl -S检查已配置的VirtualHosts - 这将打印所有已配置的VirtualHost及其相应配置文件的列表