您的主机文件看起来不错,但您的虚拟主机定义不太好。
如果您更改您的hosts 文件,您可以通过使用Runs as Administrator 启动的命令窗口或简单重启来重新加载Windows 缓存:-
net stop "DNS Client"
然后当它完成时做
net start "DNS Client"
由于服务名称中有空格,所以需要引号!!
DNS 客户端服务缓存访问的域名,并在启动时预加载存在于HOSTS 文件中的域名,或者如果您按上述方式重新启动服务。
在调试新的 vhost 定义时,请记住,如果您尝试访问的定义有问题,Apache 将始终默认为 vhost 定义文件中定义的第一个 vhost。因此,如果这就是您最终到达的地方,即 WAMP 主页,您可以假设您在定义该虚拟主机时犯了一个错误。
这也意味着,如果你用Require local 之类的东西定义第一个虚拟主机定义,你的系统上的随机黑客也应该被发送到那里,如果它的安全设置为Require local,黑客应该收到一个 404 错误可能会阻止进一步的黑客攻击。
// My virtual hosts file
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:\wamp\www"
<Directory "C:\wamp\www">
AllowOverride All
# never want to allow access to your wamp home page area to anyone other than This PC
# plus us the Apache 2.4.x syntax and not the 2.2 syntax
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName client1.localhost
DocumentRoot "C:\wamp\www\client1"
<Directory "C:\wamp\www\client1">
AllowOverride all
# use Apache 2.4 syntax to all access to your internal network only
Require ip 192.168.0
# Or if you really want to give access to the whole internet uncomment this and comment the previous line
#Require all granted
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
<VirtualHost *:80>
ServerName client2.localhost
DocumentRoot "C:\wamp\www\client2"
<Directory "C:\wamp\www\client2">
AllowOverride all
# use Apache 2.4 syntax to all access to your internal network only
Require ip 192.168.0
# Or if you really want to give access to the whole internet uncomment this and comment the previous line
#Require all granted
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
如果您实际上并不希望允许全世界访问这些客户端站点,但您确实希望能够从内部网络上的其他 PC 访问该站点,那么更好的访问机制是使用 @987654329 @。请注意仅使用子网的前 3 个四分位数(您的可能不是 192.168.0,但很多路由器默认使用该值。首先检查您的子网)
此外,如果您确实希望全世界都能看到这些客户端站点,那么您还必须Port Forward 您的路由器。
另外,如果您不打算让全世界都可以访问这些网站,而只是听从了不好的建议,那么对所有这些网站的更安全的定义是使用Require local,因此您只能访问它们来自运行 WAMP 的 PC。
WAMPServer 2.4,我假设你的意思是当你说你正在运行最新版本的 WAMPServer 时,实际上改变了你可以包含虚拟主机定义的方式。好吧,实际上它包含了一种新方式,并保留了旧方式。
因此,要包含虚拟主机定义,您可以执行以下两件事之一:-
1。
将您的 vhost 定义放入文件 \wamp\bin\apache\apache2.4.4\conf\extra\httpd-vhosts.conf and then in thehttpd.conf 文件中取消注释此行(它靠近 conf 文件的底部。
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
删除Include 行前面的#
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2。
将您的虚拟主机定义放入 \wamp\vhost 文件夹中的“您喜欢的任何名称”的文件中。
现在httpd.conf 文件底部有一行写着IncludeOptional "d:/wamp/vhosts/*"
这将包括该文件夹中的任何文件,如果它是虚拟主机定义,它将应用于配置。这是 Apache 2.4 的一个新命令,我相信它只适用于 Apache 2.4.x 安装。