VirtualDocumentRoot 和域总是路由到本地主机 - 为什么?
我试图让动态虚拟主机正常工作,按照文档进行操作,但效果不太好。
这些是我的 HOSTS 文件中的域:
127.0.0.1 walestourism.local.co.uk
127.0.0.1 www.walestourism.local.co.uk
127.0.0.2 walestourism.local.co.uk
127.0.0.2 www.walestourism.local.co.uk
这是来自 httpd.conf:
NameVirtualHost 127.0.0.2
<VirtualHost 127.0.0.2>
ServerName www.walestourism.local.co.uk
ServerAlias walestourism.local.co.uk
DocumentRoot /www/walestourism.local.co.uk
ScriptAlias /cgi-bin/ /www/walestourism.local.co.uk/cgi-bin
</VirtualHost>
在我的所有其他文件中,上述代码的 VirtualHost 部分始终是 *:80。
我的 httpd.conf 中有此代码:
<Directory C:/www/vhosts>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/vhosts1>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/vhosts.www>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/test2>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
我应该如何修复此错误,因为当我在其中键入域时,它会将我带到 http: 的内容: //本地主机?这是当我尝试使用动态虚拟主机添加域时遇到的基本问题。
另外,如果我将浏览器指向“http://localhost/”,我会得到默认的“It Works!”页面,所以我知道我的服务器正在运行,这肯定与虚拟主机配置有关。
我检查了我的错误日志 - 因此没有错误,那么为什么每个域都定向到本地主机,即使为它们配置了一个文件夹(/www/ 在本例中是 C:/www,我的 Apache/webserver 的目录)。
我是 Apache 这个领域的新手,尽管用谷歌搜索了一下午,但我不知道如何解决这个问题。
我决定尝试这个以避免执行 cmd >每次我添加新的虚拟主机进行测试时,httpd -k都会重新启动,但我做错了什么吗?
我使用的是 Apache 2.2、Windows 7、PHP 5.28 [此处提及规范]。
我应该怎么办?
非常感谢所有建议!
I'm trying to get dynamic virtual hosts to work, followed the documentation but it didn't quite work.
These are the domains from my HOSTS file:
127.0.0.1 walestourism.local.co.uk
127.0.0.1 www.walestourism.local.co.uk
127.0.0.2 walestourism.local.co.uk
127.0.0.2 www.walestourism.local.co.uk
and this is from httpd.conf:
NameVirtualHost 127.0.0.2
<VirtualHost 127.0.0.2>
ServerName www.walestourism.local.co.uk
ServerAlias walestourism.local.co.uk
DocumentRoot /www/walestourism.local.co.uk
ScriptAlias /cgi-bin/ /www/walestourism.local.co.uk/cgi-bin
</VirtualHost>
In all my other ones it was always *:80 for the VirtualHost part of the above code.
I have this code in my httpd.conf:
<Directory C:/www/vhosts>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/vhosts1>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/vhosts.www>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/test2>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
<Directory C:/www/>
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
How should I fix this error, as when I type the domain in it takes me to the contents of http://localhost ? That's the basic problem I get when I try to add domains using dynamic virtual hosts.
Also, if I point my browser to "http://localhost/", I get the default "It Works!" page, so I know that my server is running and that this is definitely something to do with the vhosts configuration.
I checked my error log - no errors as a result of this, so why does every domain direct to localhost even when there's a folder configured for them (/www/ in this case is C:/www, my Apache/webserver's directory).
I'm new to this area of Apache, and despite an afternoon of Googling, I'm not sure how to fix this.
I decided to try this to avoid doing cmd > httpd -k restart every time I add a new virtualhost for testing, but have I done anything wrong?
I'm on Apache 2.2, using Windows 7, with PHP 5.28 [mentioning specifications here].
What should I do?
All advice is very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用基于命名的虚拟主机时,不要使用 127.0.0.2 ...只需将其全部保留为 127.0.0.1 ...如果失败,请检查 apache 的 error_log (在您的 httpd.conf 中定义)以解决原因它正在失败。
此外,在开始使用 PHP 之前,请先让 Apache2 在 Windows 上使用 VHosts 工作...
按照 http://httpd.apache.org/docs/2.0/vhosts/examples.html:
As you are using named based virtual hosting, don't use 127.0.0.2 ... just keep it all to 127.0.0.1 ... failing that, check the error_log for apache (defined in your httpd.conf) to trouble shoot why it is failing.
Additionally, get Apache2 working on Windows with VHosts before you get going with PHP ...
As per http://httpd.apache.org/docs/2.0/vhosts/examples.html:
通常,如果虚拟主机配置错误,就会发生这种情况。当你在 Windows 上时,我不知道如何测试你的配置,在 Linux 上你会做类似的事情:
尝试从命令行启动 apache 并查看是否有任何错误。如果 Apache 作为服务安装,您可以在 Windows 应用程序事件日志中看到启动错误。
Normally this happens, if a virtual host is configured wrongly. As you are on windows I have no idea how to test your configuration, on linux you would do something like:
try to start apache from command line and see if you get any errors. If Apache is installed as a service you can see startup errors in the windows application event logs.