我正在运行 Ubuntu 20.0.4 LTS 虚拟服务器。我需要能够从服务器内部访问 http://localhost:9000/ 来运行我尝试运行的服务,但我一直收到“连接被拒绝”错误。
我尝试运行 telnet 到该端口并收到以下消息:
$ telnet localhost 9000
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
我知道 telnet 正在运行,因为我已经通过不同的端口成功登录(下面的 nmap 结果中显示的端口)。
检查 FW 和 iptables,该端口似乎应该是打开的:
iptables:
$ sudo iptables -L
Chain ufw-user-input (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT udp -- anywhere anywhere udp dpt:22
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:9000
ACCEPT udp -- anywhere anywhere udp dpt:9000
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT udp -- anywhere anywhere udp dpt:443
ACCEPT tcp -- anywhere anywhere tcp dpt:mysql
ACCEPT udp -- anywhere anywhere udp dpt:3306
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT udp -- anywhere anywhere udp dpt:80
ACCEPT tcp -- anywhere anywhere tcp dpt:9000
ACCEPT udp -- anywhere anywhere udp dpt:9000
前锋:
$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22 ALLOW IN Anywhere
22/tcp ALLOW IN Anywhere
9000 ALLOW IN Anywhere
443 ALLOW IN Anywhere
3306 ALLOW IN Anywhere
80 ALLOW IN Anywhere # accept Apache
9000/tcp ALLOW IN Anywhere
9000/udp ALLOW IN Anywhere
22 (v6) ALLOW IN Anywhere (v6)
22/tcp (v6) ALLOW IN Anywhere (v6)
9000 (v6) ALLOW IN Anywhere (v6)
443 (v6) ALLOW IN Anywhere (v6)
3306 (v6) ALLOW IN Anywhere (v6)
80 (v6) ALLOW IN Anywhere (v6) # accept Apache
9000/tcp (v6) ALLOW IN Anywhere (v6)
9000/udp (v6) ALLOW IN Anywhere (v6)
当我运行 nmap 时,我没有看到端口打开:
$ nmap localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2022-08-09 11:04 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000073s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
3306/tcp open mysql
附件是我的跟踪路由日志:
$ sudo tcptraceroute localhost 9000
Running:
traceroute -T -O info -p 9000 localhost
traceroute to localhost (127.0.0.1), 30 hops max, 60 byte packets
1 localhost (127.0.0.1) <rst,ack> 0.017 ms 0.005 ms 0.004 ms
编辑:
netstat 结果:
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 818/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 900/sshd: /usr/sbin
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 978/mysqld
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 947/redis-server 12
tcp6 0 0 :::22 :::* LISTEN 900/sshd: /usr/sbin
tcp6 0 0 :::443 :::* LISTEN 2401/apache2
tcp6 0 0 ::1:6379 :::* LISTEN 947/redis-server 12
tcp6 0 0 :::80 :::* LISTEN 2401/apache2
似乎我没有任何服务监听端口 9000。该如何修复?
有人能帮我诊断一下问题吗?
提前致谢。
答案1
事实证明,每次我退出 CLI 时,我运行的 gunicorn 服务器都会关闭。我通过使用守护进程使其进程在后台运行来解决这个问题。
(venv) $ gunicorn opentaxii.http:app \
> --bind localhost:9000 --config python:opentaxii.http --daemon