server { listen 8890; server_name localhost; root /usr/share/nginx/html; index index.html; # 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|woff|woff2|ttf|eot|otf)$ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; } # 前端路由支持 - 所有路由指向 index.html location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache"; } # API 代理 - 将 /api 请求转发到后端 location /api/ { proxy_pass http://scoring-backend:8876/api/; proxy_http_version 1.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_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; } # 媒体文件代理 location /media/ { proxy_pass http://scoring-backend:8876/media/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } # 静态文件代理 location /static/ { proxy_pass http://scoring-backend:8876/static/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } # 健康检查 location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # 错误页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }