如何通过局域网中的另一台电脑访问我的本地主机?

22

我正在使用WAMP服务器运行我的网站,操作系统是Windows 7。

我在两台电脑之间创建了局域网,希望从第二台电脑访问我的本地主机。
请注意,我没有使用互联网连接,因此无法使用IP地址。

请给我您的建议。


5
局域网中的计算机仍然会获得IP地址,与互联网并没有太大关系。除非您正在使用交叉线缆或类似的东西。我们需要更多细节来回答您的问题。 - Madbreaks
4个回答

10

您需要编辑 httpd.conf 文件,并找到以下行:Listen 127.0.0.1:80

然后写下您设定的局域网 IP 地址,不要使用自动获取IP地址。
例如:Listen 192.168.137.1:80

我使用 192.167.137.1 作为我的 Windows 7 的局域网 IP 地址。重启 Apache 以享受共享服务。


或者Listen *:80也可以。 - Muhammad Qasim

10

IP可以是任何局域网或广域网IP地址。但是您需要设置防火墙连接以允许它。

设备连接Web服务器PC可以通过局域网或广域网进行(即通过wifi、connectify、adhoc、电缆、我的公共wifi等)

你应该按照以下步骤操作:

  1. 进入控制面板
  2. 入站规则 > 新建规则
  3. 点击端口 > 下一步 > 指定本地端口 > 输入8080 > 下一步 > 允许连接>
  4. 下一步 > 选中所有(域、私有、公共)> 指定任意名称
  5. 现在,您可以通过任何设备(笔记本电脑、手机、台式机等)访问本地主机。
  6. 在浏览器url中输入IP地址作为123.23.xx.xx:8080,以访问本地主机。

此IP将属于具有Web服务器的设备。


这可以使用公共IP地址来完成吗?这样我就可以与世界分享了吗? - AskYous
1
请注意,上面的第1点是指从控制面板打开Windows Defender防火墙,然后按高级设置(在左侧)。 - jciloa

6

实际上,使用IP地址并不需要互联网连接。局域网中的每台计算机都有一个内部IP地址,您可以通过运行命令来发现它:

ipconfig /all

在命令提示符中。

您可以使用服务器的IP地址(可能类似于192.168.0.x或10.0.0.x)远程访问网站。

如果您找到了IP地址但仍然无法访问网站,则意味着WAMP未配置为响应该名称(你叫我什么?192.168.0.3?那不是我的名字。我是本地主机),您需要修改....../apache/config/httpd.conf

Listen *:80

0

您的电脑连接到其他电脑后,请按照以下4个步骤进行操作:
4个步骤:
1- 编辑此文件:httpd.conf
为此,请单击WAMP服务器,选择Apache并选择httpd.conf
2- 查找此文本:Deny from all
在下面的标记中:

  <Directory "c:/wamp/www"><!-- maybe other url-->

    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
#    Require all granted
#   onlineoffline tag - don't remove
     Order Deny,Allow
    Deny from all
     Allow from 127.0.0.1
     Allow from ::1
     Allow from localhost
</Directory>

3- 将 Change 改为:Deny from none
如下所示:

<Directory "c:/wamp/www">

    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
#    Require all granted
#   onlineoffline tag - don't remove
     Order Deny,Allow
    Deny from none
     Allow from 127.0.0.1
     Allow from ::1
     Allow from localhost

4- 重启 Apache
别忘了重启 Apache 或所有服务!!!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接