我刚刚意识到WAMP上没有任何其他内容可以访问,除非它位于虚拟主机别名下。例如:如果我将vHost命名为'mysite.dev',我只能访问mysite.dev,其他一切都会出现403禁止错误。如果我在mysite.dev之外添加名为anothersite.dev的vHost,则只能访问这些网站。我可以访问localhost下唯一的东西是PHPMyAdmin。我已经取消注释了包含Apache httpd.conf文件中的vHosts.conf的行。直到我修改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主机文件:
127.0.0.1 localhost
127.0.0.1 mysite.dev
答案 0 :(得分:2)
好的,首先,httpd-vhost.conf
文件中的前2个VHOST定义(vhost和vhost2)是Apache提供的示例,以帮助您入门,当然还指向不存在的文件夹< / strong>所以应该删除。
第二,创建虚拟主机时,应在<Directory....>
组中包含VHOST的访问权限。
第三,你应该一直为localhost创建一个VHOST,因为一旦创建了VHOST,Apache就会忽略httpd.conf
中的localhost定义
因此,您的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>
完成此操作后,您现在需要编辑c:\windows\system32\drivers\etc\hosts
文件,使其如下所示。您需要具有管理员权限来编辑此文件,一些反病毒套件也会保护此文件,因此您可能需要暂时停止该保护以修改此文件。
127.0.0.1 localhost
127.0.0.1 mysite.dev
::1 localhost
::1 mysite.dev
然后重新启动dnscache以从管理员权限启动的命令行中获取这些更改。
net stop dnscache
net start dnscache
这篇文章可以帮助您understand more about Virtual Hosts