如何修复此虚拟主机设置?

时间:2009-03-25 23:10:41

标签: linux apache http centos

我已经在运行apache 2的centos服务器上设置了2个共享相同IP的虚拟主机。

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/a
    ServerName www.a.com
    ServerAlias a.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/b
    ServerName www.b.com
    ServerAlias b.com
</VirtualHost>

无论我指向哪个网址。站点A出现。

我该如何解决?我应该让a.com去a和b.com去b。

全部谢谢

3 个答案:

答案 0 :(得分:6)

httpd.conf中是否设置了以下内容?

NameVirtualHost *

来自documentation

的示例
NameVirtualHost *

<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

答案 1 :(得分:2)

确保你也有这个指令

NameVirtualHost *

它可能正在显示站点A,因为它被设置为默认文档根目录。检查全局设置,确保文档根目录未设置为与站点A相同的根目录。

答案 2 :(得分:2)

我总是将域名声明为名称..从来没有问题。

NameVirtualHost localhost:80

<VirtualHost localhost:80>
DocumentRoot "/home/eddie/workspace/"
</VirtualHost>

<VirtualHost digbiz.localhost:80>
DocumentRoot "/home/eddie/workspace/Digital_Business/app/webroot"
</VirtualHost>

<VirtualHost wishlist.localhost:80>
DocumentRoot "/home/eddie/workspace/WishList/app/webroot"
</VirtualHost>

<VirtualHost phpmyadmin.localhost:80>
DocumentRoot "/srv/www/phpMyAdmin"
</VirtualHost>


<VirtualHost test.localhost:80>
DocumentRoot "/home/eddie/workspace/CakePHPTesting/app/webroot"
</VirtualHost>

<VirtualHost auth.localhost:80>
DocumentRoot "/home/eddie/workspace/EntMeetCapt/app/webroot"
</VirtualHost>