【问题标题】:Apache: How can i see my localhost on 192.168.1.101 from 192.168.1.102?Apache:如何从 192.168.1.102 看到我在 192.168.1.101 上的本地主机?
【发布时间】:2011-05-30 09:22:40
【问题描述】:

我在 Ubuntu 上运行 Apache。我的 IP 地址是 192.168.1.101

虽然http://localhosthttp://192.168.1.101 在我的PC 中工作正常,但我无法使用http://192.168.1.102 从我的笔记本电脑中访问它

这很奇怪。我可以 ping 192.168.1.101 但我得到“连接超时。”在浏览器中。

我正在使用默认的 apache 配置。所以这就是我的sites-available/default 的样子:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /home/www/public_html
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/www/public_html>
        Options Indexes FollowSymLinks MultiViews
        #AllowOverride None
        AllowOverride all
        Order allow,deny
        allow from all

    </Directory>

/etc/apache2/posrts.conf 名称虚拟主机 *:80 听 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

我的笔记本电脑也运行 Ubuntu。所以我认为这不是防火墙问题。

在笔记本电脑 (192.168.1.102) 中执行的命令:

adp@adp-laptop:~$ ping 192.168.1.101
PING 192.168.1.101 (192.168.1.101) 56(84) bytes of data.
64 bytes from 192.168.1.101: icmp_seq=1 ttl=64 time=32.1 ms
64 bytes from 192.168.1.101: icmp_seq=2 ttl=64 time=54.8 ms
64 bytes from 192.168.1.101: icmp_seq=3 ttl=64 time=77.0 ms
64 bytes from 192.168.1.101: icmp_seq=4 ttl=64 time=100 ms
^C
--- 192.168.1.101 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 32.193/66.193/100.717/25.463 ms

adp@adp-laptop:~$ telnet 192.168.1.101 80
Trying 192.168.1.101...
telnet: Unable to connect to remote host: Connection timed out

在 PC (192.168.1.101) 中执行的命令:

adp@adp-desktop:~$ ps afx | grep http
12672 pts/4    S+     0:00              |               \_ grep --color=auto http

adp@adp-desktop:~$ ping 192.168.1.102
PING 192.168.1.102 (192.168.1.102) 56(84) bytes of data.
64 bytes from 192.168.1.102: icmp_seq=1 ttl=64 time=32.1 ms
64 bytes from 192.168.1.102: icmp_seq=2 ttl=64 time=54.8 ms
64 bytes from 192.168.1.102: icmp_seq=3 ttl=64 time=77.0 ms
64 bytes from 192.168.1.102: icmp_seq=4 ttl=64 time=100 ms
^C
--- 192.168.1.102 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 32.193/66.193/100.717/25.463 ms
adp@adp-desktop:~$ telnet 192.168.1.102 80
Trying 192.168.1.102...
telnet: Unable to connect to remote host: Connection refused
adp@adp-desktop:~$ telnet 192.168.1.102
Trying 192.168.1.102...
telnet: Unable to connect to remote host: Connection refused

我该怎么办?

【问题讨论】:

  • 你的 /etc/apache2/ports.conf 中有什么?
  • @takpar -ps afx | grep http 在两台电脑上
  • @aeby 和 @ajreal:我在问题中提供了请求的信息。谢谢。
  • 我认为是网络问题。从 Apache 的角度来看不是问题。是否检查过 192.168.1.101:80 是否可以从其他 PC 访问?
  • “192.168.1.101:80 无法从其他 PC 访问”。这就是问题所在。

标签: apache apache2


【解决方案1】:

因为连接超时(没有被拒绝)我猜这是一个防火墙问题检查你是否正在使用任何。

如果您的内核使用 黑洞 来关闭端口(它不发送连接被拒绝 TCP 数据包只是拒绝回答任何内容,如果端口未使用)。但是你提到你的配置文件中有Listen 80,这意味着所有接口,所以你很可能有防火墙问题。

在 UFW(Ubuntu 中的默认防火墙)中,您可以添加防火墙规则以允许传入的 HTTP 连接到您的机器:

sudo ufw allow proto tcp from any to 192.168.1.101 port 80

【讨论】:

  • UFW 是 Ubuntu 中的默认防火墙。如果您驻留在 Intranet 上,则几乎不需要它(因为您的路由器无论如何都是天然防火墙)。您可以使用以下命令禁用它:sudo ufw disable,但我在答案中添加了一条 UFW 规则(未测试)。
猜你喜欢
  • 2012-03-07
  • 1970-01-01
  • 2011-05-13
  • 2016-07-31
  • 1970-01-01
  • 2019-02-12
  • 2013-08-24
  • 2013-03-13
  • 1970-01-01
相关资源
最近更新 更多