从另一台计算机访问虚拟主机 [英] Access virtual host from another machine

查看:242
本文介绍了从另一台计算机访问虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows 7 WAMP 2.2服务器。结果
我已经安装2虚拟主机www.project1.com和www.project2.com。结果
我已经加入到主机文件中这些条目,并在httpd.conf中所需的条目和的httpd-vhosts.conf文件。结果
使用我的浏览器,当我键入www.project1.com或www.project2.com,我得到与服务器的笔记本电脑打开我的网页。

I am using windows 7 with Wamp 2.2 server.
I have setup 2 virtual hosts www.project1.com and www.project2.com.
I have added these entries in the hosts file and the required entries in the httpd.conf and httpd-vhosts.conf file.
Using my browser, when i type www.project1.com or www.project2.com, i get my web page opened on the laptop with the server.

在hosts文件中的变化。在该文件的末尾追加: -

Changes in hosts file. Appended at the end of the file:-

127.0.0.1       localhost
127.0.0.1       www.project2.com
127.0.0.1       www.project1.com

在httpd.conf文件中的变化: -

Changes in httpd.conf file:-

Include conf/extra/httpd-vhosts.conf

在的httpd的虚拟主机文件的变化: -

Changes in httpd-vhosts file:-

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.com
</VirtualHost>


<VirtualHost 127.0.0.1>
    DocumentRoot "D:/websites/project2/"
    ServerName www.project2.com
</VirtualHost>

现在,因为我可以打开PC_1的(一个与服务器)浏览这些网页,我怎么能访问这些网页从PC_2的浏览器(通过LAN连接到PC1任何PC)?

Now since i can open these web pages from PC_1's(the one with the server) browser, how can i access these web pages from PC_2's browser(any PC connected to PC1 via LAN)?

推荐答案

在您的虚拟主机的指令,将 127.0.0.1 *:80 和加布里埃尔提到,到主机中的其他计算机文件,添加你自己的域名与您的服务器的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.com
</VirtualHost>

如果你的服务器是192.168.1.70例如,然后在你的局域网的其他机器的主机条目如下:

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.com

重启Apache,它应该工作的罚款。

Restart apache and it should work fine.

作为一个说明,当您使用virtualhosts,阿帕奇将使用第一个定义为默认值时,它无法在HTTP请求头中传递域和站点设置的配置,这是之间的匹配为什么你的默认页的显示。

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.

您告诉阿帕奇绑定到所有IP与了NameVirtualHost *:80 指令,但当时并没有设置一个网站的外部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!

这篇关于从另一台计算机访问虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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