server { listen 3000; server_name localhost; root /usr/share/nginx/html; index index.html; # 上傳大小限制(模型檔最大 500MB) client_max_body_size 500m; # 啟用gzip壓縮 gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json; # 靜態文件緩存 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires 1y; add_header Cache-Control "public, immutable"; } # SSE 端點 — 必須關閉 buffering(rewrite /api → /) location ~ ^/api/(jobs/.*/events)$ { proxy_pass http://scheduler:4000/$1; 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; proxy_buffering off; proxy_cache off; proxy_read_timeout 86400s; proxy_send_timeout 86400s; chunked_transfer_encoding on; gzip off; } # API 代理(rewrite /api → /) location /api/ { proxy_pass http://scheduler:4000/; 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; } # SPA路由支持 location / { try_files $uri $uri/ /index.html; } # 安全頭 add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; }