
我正在嘗試在 Ubuntu 虛擬機器上運行一個簡單的 Flask 伺服器。
我可以使用 ssh 進入它,[email protected]
但是如果我執行,curl 123.456.789:8000
即使伺服器正在偵聽,我也會遇到操作逾時:
* Serving Flask app "app.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:8000/ (Press CTRL+C to quit)
我的iptables -vnL
輸出如下圖所示:
Chain INPUT (policy ACCEPT 11434 packets, 8571K bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8000
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 7590 packets, 4856K bytes)
pkts bytes target prot opt in out source destination
所以連接埠 8000 應該可以使用。我lsof
也可以看到它:
flask 16268 robin 3u IPv4 167958 0t0 TCP 127.0.0.1:8000 (LISTEN)
我以前沒有真正這樣做過,所以這可能是一個愚蠢的錯誤,但是你能想到這裡還有其他可能出錯的地方嗎?
答案1
python/flask 應用程式正在偵聽 127.0.0.1,因此限制對本機的存取。
讓它監聽特定的 IP 或 0.0.0.0,取決於您的需求。