WAMP上的虚拟主机导致403在本地主机上被禁止...其他别名仍然有效 [英] Virtual Hosts on WAMP causing 403 forbidden on localhost... other aliases still work

查看:113
本文介绍了WAMP上的虚拟主机导致403在本地主机上被禁止...其他别名仍然有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是意识到,除非位于虚拟主机别名下,否则WAMP上的其他内容均不可访问.例如:如果我将vHost命名为"mysite.dev",则只能访问mysite.dev,其他所有内容都将显示403禁止错误.如果除了mysite.dev之外还添加了一个名为anothersite.dev的vHost,则只能访问那些站点.我可以访问的在localhost下的唯一内容是PHPMyAdmin.我已取消注释Apache httpd.conf文件中包含vHosts.conf的行.在修改vHosts.conf文件之前,不会发生此问题.这是其他文件的配置:

I just realized that nothing else on WAMP is accessible unless it's under the virtual host alias. For example: if I name my vHost 'mysite.dev', I can only access mysite.dev and everything else gives a 403 forbidden error. If I add a vHost called anothersite.dev in addition to mysite.dev, only those sites can be accessed. The only thing under localhost that I can access is PHPMyAdmin. I have uncommented the line that includes vHosts.conf in the Apache httpd.conf file. This problem does not happen until I modify the vHosts.conf file. Here is the config for the other files:

vHosts.conf:

vHosts.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "W:/wamp/www/mysite"
    ServerName mysite.dev
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

Windows主机文件:

Windows hosts file:

127.0.0.1       localhost
127.0.0.1   mysite.dev

推荐答案

好吧,httpd-vhost.conf文件(vhost和vhost2)中的前两个VHOST定义是Apache提供的示例,可帮助您入门和学习.当然会指向不存在的文件夹 ,因此应删除.

Ok first, the first 2 VHOST definitions in the httpd-vhost.conf file (vhost and vhost2) are examples, supplied by Apache, to help you get started and of course point to folders that do not exist so and should be removed.

第二个当您创建虚拟主机时,您应该在<Directory....>组中包括VHOST的访问特权.

Second When you create a Virtual Host you should include the access privilages for the VHOST in a <Directory....> group.

第三,您应该始终为localhost创建一个VHOST,因为一旦创建了VHOST,Apache就会忽略httpd.conf

Third, you should always create a VHOST for localhost as once VHOSTs are created Apache ignores the localhost definition in httpd.conf

因此,您的httpd-vhost.conf文件应如下所示:

So your httpd-vhost.conf file should look like this

# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
    ServerAdmin webmaster@homemail.net
    DocumentRoot "W:/wamp/www"
    ServerName localhost
    <Directory  "W:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "W:/wamp/www/mysite"
    ServerName mysite.dev
    ErrorLog "logs/mysite.dev-error.log"
    CustomLog "logs/mysite.dev-access.log" common
    <Directory  "W:/wamp/www/mysite">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

完成此操作后,现在需要编辑c:\windows\system32\drivers\etc\hosts文件,如下所示.您需要具有管理员特权才能编辑此文件,而且某些防病毒套件也可以保护此文件,因此您可能需要暂时停止该保护才能修改此文件.

Once you have done this, you now need to edit your c:\windows\system32\drivers\etc\hosts file to look like this. You need to have admin privilages to edit this file, also some anti virus suites also protect this file, so you may need to stop that protection temporarily in order to amend this file.

127.0.0.1  localhost
127.0.0.1  mysite.dev

::1  localhost
::1 mysite.dev

然后从也以管理员权限开始的命令行中重新启动dnscache以获取这些更改.

Then restart the dnscache to pick up these changes, from a command line also started with admin privilages.

net stop dnscache
net start dnscache

这篇文章可能会帮助您了解有关虚拟的更多信息主机

This post may help you understand more about Virtual Hosts

这篇关于WAMP上的虚拟主机导致403在本地主机上被禁止...其他别名仍然有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆