通过 LAN 从另一台机器访问虚拟主机 [英] Access virtual host from another machine over LAN

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

问题描述

  • 我正在使用带有 Wamp 2.2 服务器的 Windows 7.
  • 我设置了 2 个虚拟主机:www.project1.comwww.project2.com.
  • 我已修改主机",httpd.confhttpd-vhosts.conf 文件,我在下面提到的更改.

使用我的浏览器,当我输入 www.project1.comwww.project2.com 时,我成功地在有服务器的笔记本电脑上打开了我的网页安装在.

Using my browser, when I type www.project1.com or www.project2.com, I successfully get my web pages opened on the laptop that has the server installed on.

hosts 文件"中的更改:我在文件末尾附加了以下内容:-

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.com
127.0.0.1       www.project1.com

httpd.conf 文件的变化:-

Include conf/extra/httpd-vhosts.conf

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


<VirtualHost 127.0.0.1>
    DocumentRoot "D:/websites/project2/"
    ServerName www.project2.com
</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.com
</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.com

重新启动 apache,它应该可以正常工作.

Restart apache and it should work fine.

请注意,当您使用虚拟主机时,当无法在 HTTP 请求标头中传递的域和配置中设置的站点之间进行匹配时,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 从另一台机器访问虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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