This commit is contained in:
beabigegg
2025-09-12 08:54:21 +08:00
parent a2f024704c
commit 5ad4035e02
8 changed files with 246 additions and 364 deletions

View File

@@ -0,0 +1,40 @@
# 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 參數(現行)
```bash
--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、靜態快取
## 啟動
```bash
docker-compose up --build -d
# 確認
curl http://localhost:12011/api/health/
```
## 備註
- 若需 TLS/443請在 `nginx/nginx.conf` 中加入對應的 server 區塊與憑證設定。
- `todolist-app` 不再對外曝露 Port請僅對外開放 12011。