【问题标题】:listen on port 80 but can't access from public using nginx on centos 7.1在端口 80 上侦听,但无法在 centos 7.1 上使用 nginx 从公共访问
【发布时间】:2026-01-13 14:00:05
【问题描述】:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16146/nginx: master

nginx 确实监听了 80 端口。这是我在 /etc/nginx/conf.d/default.conf 中的配置

server {
    listen       80;
    server_name  _;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ { ...

我正在使用公共 ip 在云主机上运行 nginx,但由于连接超时,我无法从公共网络访问该 ip。

【问题讨论】:

    标签: nginx centos


    【解决方案1】:

    首先: 使用 tcpdump 检查您是否尝试连接您需要的服务器。
    在目标服务器:
    tcpdump -i your_wan_if port 80(例如:tcpdump -i venet0 port 80
    在本地主机:
    telnet external_ip 80
    如果你会从你的 ip 看到任何活动 - 很好。

    第二:
    检查 selinux 和防火墙。尝试禁用它们片刻并检查。

    (如果你知道如何配置 iptables - 去做吧。不知道 - 使用谷歌。不想谷歌 - 使用这个: iptables -I INPUT 4 -p tcp --dport 80 -j ACCEPT)

    【讨论】:

    • 谢谢!这是一个防火墙的东西。