当我不在localhost中时,我无法在端口80上连接到我的Web服务器,在带有nginx 1.14.2的debian 9上。
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.
不幸的是,在运行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
返回:
Trying addr...
telnet: Unable to connect to remote host: Connection refused
我尝试使用ip6tables -P INPUT ACCEPT
、ip6tables -P OUTPUT ACCEPT
和ip6tables -A INPUT -p tcp --dport 80 -j ACCEPT
添加规则,但现在似乎不起作用。我还删除了所有IPv6规则,没有更改。
我咨询了以下几种方法,但至今没有一种奏效:
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
1条答案
按热度按时间z0qdvdin1#
看来我只是有点愚蠢,真的不习惯网络服务器配置,我错过了我的服务器的配置,它落在默认的nginx服务器,这是可悲的是只监听端口80上的IPv4。只是另一个愚蠢的错误,热烈感谢@彼得罗斯,谁设置我的正确轨道。