- 我正在将Windows 7与Wamp 2.2服务器一起使用.
- 我设置了2个虚拟主机:www.project1和www.project2.
- 我修改了" 主机 ", httpd.conf 和 httpd-vhosts.conf 文件,进行我在下面提到的更改.
- I am using Windows 7 with Wamp 2.2 server.
- I have setup 2 virtual hosts: www.project1 and www.project2.
- I have modified the "hosts", the httpd.conf, and the httpd-vhosts.conf files, to the changes I mentioned below.
使用浏览器,当我键入www.project1或www.project2时,我成功地在装有服务器的笔记本电脑上打开了网页.
Using my browser, when I type www.project1 or www.project2, I successfully get my web pages opened on the laptop that has the server installed on.
"主机文件"中的更改:我在文件末尾附加了以下内容:-
Changes in the "hosts file": I've appended the followings to the end of the file:-
127.0.0.1 localhost 127.0.0.1 www.project2 127.0.0.1 www.project1httpd.conf文件中的更改:-
Include conf/extra/httpd-vhosts.confhttpd-vhosts文件中的更改:-
NameVirtualHost *:80 <Directory "D:/websites/"> AllowOverride All Order Deny,Allow Allow from all </Directory> <VirtualHost 127.0.0.1> DocumentRoot "D:/websites/wamp/www/" ServerName localhost </VirtualHost> <VirtualHost 127.0.0.1> DocumentRoot "D:/websites/project1/" ServerName www.project1 </VirtualHost> <VirtualHost 127.0.0.1> DocumentRoot "D:/websites/project2/" ServerName www.project2 </VirtualHost>现在;由于可以从PC_1中的浏览器(带有服务器的浏览器)打开这些网页,因此如何从PC_2中的浏览器访问这些网页? (我的意思是任何通过LAN连接到PC_1的PC.)
Now; since I can open these web pages from a browser in PC_1 (the one with the server), how can I access these web pages from a browser in PC_2? (I mean any PC connected to PC_1 via LAN.)
推荐答案在您的virtualhost指令中,将127.0.0.1更改为*:80,并如Gabriel所述,在另一台计算机上的hosts文件中添加一个条目,从而添加您的域与您服务器的IP相关联.
In your virtualhost directive, change 127.0.0.1 to *:80 and as Gabriel mentioned, add an entry to the hosts file in the other machine, adding your domain to be associated with the IP of your server.
当您在指令中添加显式IP时,apache将仅侦听该IP-但通配符将告诉它绑定到它可用的所有IP.
When you put an explicit IP into the directive, apache will only listen on that IP - but the wildcard will tell it bind to all IPs available to it.
<VirtualHost *:80> DocumentRoot "D:/websites/project1/" ServerName www.project1 </VirtualHost>例如,如果您的服务器位于192.168.1.70上,则在局域网上的其他计算机上,hosts条目将如下所示:
If your server is on 192.168.1.70 for example, then in the other machines on your lan, the hosts entry will look like:
192.168.1.70 www.project1重新启动apache,它应该可以正常工作.
Restart apache and it should work fine.
请注意,当您使用虚拟主机时,当无法在HTTP请求标头中传递的域与config中的站点设置之间进行匹配时,apache将使用第一个定义作为默认设置.为什么显示默认页面.
As a note, when you are using virtualhosts, apache will use the first definition as a default for when it can't make a match between the domain passed in the HTTP request header and the sites setup in the config, which is why your default page was appearing.
您告诉Apache使用NameVirtualHost *:80指令绑定到所有IP,但是没有为该外部IP设置站点.希望有帮助!
You told apache to bind to all IPs with the NameVirtualHost *:80 directive, but then didn't setup a site for that external IP. Hope that helps!
更多推荐
通过LAN从另一台计算机访问虚拟主机
发布评论