
我有一個在開發伺服器上運行的 Django 項目,我正在嘗試將其移至 Ubuntu 生產伺服器。我已經開始,並取得了明顯的成功,“python manage.py run_gunicorn 0.0.0.0:8000”,但我嘗試通過常規瀏覽器連接到它指出http://JonathansCorner.com:8000/正在超時。 (當我手動執行「telnet localhost 8000」並發出 GET 請求時,它會列印出適當的 HTML。)UFW 已停用。
我該如何從外部獲取連接埠 80 上的 Gunicorn?
答案1
我有三件事供你考慮:
首先,關於你的防火牆,看起來像你做有某種防火牆正在運行,因為連接埠 8000 被「過濾」:
~ nmap jonathanscorner.com -p 8000
Starting Nmap 6.40 ( http://nmap.org ) at 2014-01-14 09:53 CST
Nmap scan report for jonathanscorner.com (54.218.143.2)
Host is up (0.10s latency).
rDNS record for 54.218.143.2: ec2-54-218-143-2.us-west-2.compute.amazonaws.com
PORT STATE SERVICE
8000/tcp filtered http-alt
其次,看起來這是在EC2上運行的?在這種情況下,您需要修改安全群組以允許此流量。
第三,直接暴露gunicorn通常不是一個好主意。讓gunicorn 監聽localhost:8000
(就像你一樣),然後使用適當的Web 伺服器來代理對gunicorn 的請求。
例如,安裝nginx,並有它偵聽連接埠 80,然後將請求代理程式到 Gunicorn 上localhost:8000
。