1.3 KiB
1.3 KiB
Nginx 反向代理與對外 Port 12011(部署更新)
本專案現已於 Docker Compose 中加入 nginx
服務作為對外入口,並統一只開放 12011
。此更新提升連線穩定度與可擴充性,適用約 200 名同時使用者。
架構與 Port
nginx
:對外12011:12011
,反向代理到todolist-app:12011
。todolist-app
:Flask API + 前端靜態檔;僅在容器網路內對 Nginx 提供服務。- 存取網址:
http://localhost:12011
- CORS 預設允許:
http://localhost:12011
,http://127.0.0.1:12011
Gunicorn 參數(現行)
--bind 0.0.0.0:12011
--worker-class gthread
--workers 4
--threads 8
--timeout 120
--keep-alive 10
--max-requests 2000
--max-requests-jitter 200
--forwarded-allow-ips *
並發估算:4 workers × 8 threads ≈ 32(可依 CPU 調整)。
Nginx 設定檔
- 路徑:
nginx/nginx.conf
- 監聽:
listen 12011;
- 反代:
/api/*
與其餘路由至todolist-app:12011
- 已啟用 gzip、keepalive 與代理緩衝;可依需要擴充(例如 TLS/HTTP2、靜態快取)
啟動
docker-compose up --build -d
# 確認
curl http://localhost:12011/api/health/
備註
- 若需 TLS/443,請在
nginx/nginx.conf
中加入對應的 server 區塊與憑證設定。 todolist-app
不再對外曝露 Port,請僅對外開放 12011。