2025-12-05 20:51:22 +08:00
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name localhost;
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
index index.html;
|
|
|
|
|
|
2025-12-16 16:58:50 +08:00
|
|
|
# 允许上传大文件(用于 ZIP 项目上传)
|
|
|
|
|
client_max_body_size 500M;
|
|
|
|
|
|
2025-12-05 20:51:22 +08:00
|
|
|
# 处理 SPA 路由
|
|
|
|
|
location / {
|
|
|
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 代理 API 请求到后端
|
|
|
|
|
location /api/ {
|
|
|
|
|
proxy_pass http://backend:8000/api/;
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
2025-12-15 16:13:47 +08:00
|
|
|
|
|
|
|
|
# ========== SSE 流式传输必需配置 ==========
|
|
|
|
|
# 禁用代理缓冲,确保事件实时推送
|
|
|
|
|
proxy_buffering off;
|
|
|
|
|
proxy_cache off;
|
|
|
|
|
|
|
|
|
|
# 明确告知 Nginx 不要缓冲 (对上游 FastAPI 的 X-Accel-Buffering 头也有效)
|
|
|
|
|
proxy_set_header X-Accel-Buffering no;
|
|
|
|
|
|
|
|
|
|
# 支持 chunked 编码
|
|
|
|
|
chunked_transfer_encoding on;
|
|
|
|
|
|
|
|
|
|
# SSE 长连接超时配置
|
|
|
|
|
proxy_read_timeout 300s; # 5 分钟读取超时 (与后端 max_idle 一致)
|
|
|
|
|
proxy_connect_timeout 10s;
|
|
|
|
|
proxy_send_timeout 60s;
|
|
|
|
|
|
|
|
|
|
# 保持连接
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Connection '';
|
2025-12-05 20:51:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 缓存静态资源
|
|
|
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
|
|
|
|
|
expires 1y;
|
|
|
|
|
add_header Cache-Control "public, immutable";
|
|
|
|
|
}
|
|
|
|
|
}
|