简体   繁体   English

WAMP上的虚拟主机导致403在本地主机上被禁止...其他别名仍然有效

[英]Virtual Hosts on WAMP causing 403 forbidden on localhost… other aliases still work

I just realized that nothing else on WAMP is accessible unless it's under the virtual host alias. 我只是意识到,除非位于虚拟主机别名下,否则WAMP上的其他内容均不可访问。 For example: if I name my vHost 'mysite.dev', I can only access mysite.dev and everything else gives a 403 forbidden error. 例如:如果我将我的vHost命名为“ mysite.dev”,则我只能访问mysite.dev,其他所有内容都将显示403禁止错误。 If I add a vHost called anothersite.dev in addition to mysite.dev, only those sites can be accessed. 如果在mysite.dev之外添加了一个名为anothersite.dev的vHost,则只能访问那些站点。 The only thing under localhost that I can access is PHPMyAdmin. 我可以访问的在localhost下的唯一内容是PHPMyAdmin。 I have uncommented the line that includes vHosts.conf in the Apache httpd.conf file. 我已取消注释Apache httpd.conf文件中包含vHosts.conf的行。 This problem does not happen until I modify the vHosts.conf file. 在修改vHosts.conf文件之前,不会发生此问题。 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 hosts file: Windows主机文件:

127.0.0.1       localhost
127.0.0.1   mysite.dev

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 . 好的,首先, httpd-vhost.conf文件中的前两个VHOST定义(vhost和vhost2)是Apache提供的示例,可以帮助您入门,当然也指向不存在的文件夹应将其删除

Second When you create a Virtual Host you should include the access privilages for the VHOST in a <Directory....> group. 其次,当您创建虚拟主机时,应在<Directory....>组中包括VHOST的访问权限。

Third, you should always create a VHOST for localhost as once VHOSTs are created Apache ignores the localhost definition in httpd.conf 第三,一旦创建VHOST,就应该始终为localhost创建VHOST Apache会忽略httpd.conf的localhost定义

So your httpd-vhost.conf file should look like this 因此,您的httpd-vhost.conf文件应如下所示

# 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>

Once you have done this, you now need to edit your c:\\windows\\system32\\drivers\\etc\\hosts file to look like this. 完成此操作后,现在需要编辑c:\\windows\\system32\\drivers\\etc\\hosts文件,使其看起来像这样。 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

Then restart the dnscache to pick up these changes, from a command line also started with admin privilages. 然后从也以admin特权开始的命令行中重新启动dnscache以获取这些更改。

net stop dnscache
net start dnscache

This post may help you understand more about Virtual Hosts 这篇文章可以帮助您了解有关虚拟主机的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM