无法在端口 80 上卷曲网络服务器(使用 Nginx)

Fail to curl webserver on port 80 (using Nginx)

当我不在本地主机上时,在带有 nginx 1.14.2 的 debian 9 上,我无法连接到端口 80 上的网络服务器。我用

卷曲 IPv6 地址
curl 'http://[addr]'

我受到

的欢迎
curl: (7) Failed to connect to addr port 80: Connection refused

我有最基本的服务器配置:

server {
    listen 80;
    listen [::]:80;

    server_name mywebserver.com www.mywebsever.com; #Those are not the real domain names

    root  /data/www/;
    index index.html;

    location / {
    }
}

tcptraceroute6 addr 80 给我以下输出,所以我很确定它来自服务器:

traceroute to addr (addr) from addr, port 80, from port 64245, 30 hops max, 60 bytes packets
 1  rpi4.home (addr)  0.029 ms [closed]  0.014 ms  0.012 ms

我禁用了 ufw 并使用 :

重置了我的 IPtables
#!/bin/sh
echo "Flushing iptables rules..."
sleep 1
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

但它仍然被阻止并且 tcptraceroute6 显示相同的错误。

我的 iptables 如下 (sudo iptables -t nat -nvL):

Chain PREROUTING (policy ACCEPT 5 packets, 850 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 1 packets, 67 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 1 packets, 67 bytes)
 pkts bytes target     prot opt in     out     source               destination

Nginx 运行 :

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2021-12-25 23:09:37 UTC; 1h 7min ago
     Docs: man:nginx(8)
  Process: 558 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 562 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 563 (nginx)
    Tasks: 2 (limit: 4915)
   Memory: 12.5M
   CGroup: /system.slice/nginx.service
           ├─ 563 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─1278 nginx: worker process

Dec 25 23:09:36 rpi4-20210210 systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 25 23:09:37 rpi4-20210210 systemd[1]: Started A high performance web server and a reverse proxy server.

不幸的是,在运行ning netstat -ntl之后,服务器似乎没有监听IPv6中的80端口:

Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:6010                :::*                    LISTEN     
tcp6       0      0 ::1:6011                :::*                    LISTEN

telnet addr 80 returns :

Trying addr...
telnet: Unable to connect to remote host: Connection refused

我尝试使用 ip6tables -P INPUT ACCEPT ip6tables -P OUTPUT ACCEPTip6tables -A INPUT -p tcp --dport 80 -j ACCEPT 添加规则,但它现在似乎不起作用。我还删除了所有 IPv6 规则,没有任何变化。

我参考了以下内容,到今天none工作了:

https://serverfault.com/questions/670575/failed-to-connect-to-127-0-0-1-port-80

https://askubuntu.com/questions/676434/port-80-connection-refused

nginx not listening to port 80

看来我只是有点笨,真的不习惯网络服务器配置,我错过了我的服务器配置,它落在默认的 nginx 服务器上,遗憾的是它只监听 IPv4 上的端口 80。又一个愚蠢的错误,非常感谢@Petros,他让我走上了正确的道路。