本文介绍了Apache服务器2.2上运行两个虚拟主机。*总是转到第一个的文档根目录任何服务器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在独立文档根目录我的httpd.conf文件两个虚拟主机在同一顺序如下图所示。

I have two virtual hosts in my httpd.conf file with separate docroots as shown below in same order.

<VirtualHost *.80>
DocumentRoot E:\docroot1    
ServerName www.development1.local
</VirtualHost>

<VirtualHost *.80>
DocumentRoot E:\docroot2
ServerName www.development2.local   
</VirtualHost>

在理想情况下,当我打www.development1.local应该告诉我的E:\\ docroot1内容,当我打www.development2.local应该告诉我的E:\\ docroot2内容。这两个网址,在我的主机文件中设置为127.0.0.1

Ideally when I hit www.development1.local it should show me the E:\docroot1 contents and when I hit www.development2.local it should show me the E:\docroot2 contents. Both these urls are set in my hosts file at 127.0.0.1

我的问题是,无论我的网址输入任www.development1.local或www.development2.local它总是显示我的E:\\ docroot1内容。如果我改变httpd.conf文件虚拟主机的顺序就说明了E:\\ docroot2内容。这意味着它总是转到第一个虚拟主机。

My problem is that whatever url I type either www.development1.local or www.development2.local it always shows me E:\docroot1 contents. If I change the order of virtual hosts in httpd.conf file then it shows the E:\docroot2 contents. That means it always goes to first virtual host.

推荐答案

这是因为你的服务器名是 www.development2.local ,这是不一样的只是 development2.local 。如果没有虚拟主机URL中的究竟的,第一个虚拟主机将用于匹配的主机名。添加

That's because your server name is www.development2.local, which is not the same as just development2.local. When there is no virtual host matching the hostname in the URL exactly, the first virtual host will be used. Add

ServerAlias development2.local

如果你想用这个名字了。

if you want to use that name too.

这篇关于Apache服务器2.2上运行两个虚拟主机。*总是转到第一个的文档根目录任何服务器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 22:21