server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; index index.html; # Docker 容器运行正常的检查地址,供 Jenkins 使用。 location = /healthz { default_type text/plain; return 200 "ok\n"; } location = /runtime-config.js { add_header Cache-Control "no-cache, no-store, must-revalidate" always; add_header Pragma "no-cache" always; add_header Expires "0" always; try_files $uri =404; } # 前端代码中的 API 前缀为 /api;保持原始路径转给 Gateway。 location /api/ { client_max_body_size 12m; proxy_pass ${API_UPSTREAM}; 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; } # 海外业务使用独立 Gateway;将浏览器前缀改写为 Gateway 的 /api 前缀。 location /overseas-api/ { client_max_body_size 12m; rewrite ^/overseas-api/(.*)$ /api/$1 break; proxy_pass ${OVERSEAS_API_UPSTREAM}; 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; } # HTML must be revalidated on every visit so a new deployment cannot keep # referencing hashed chunks that were removed with the previous image. location = /index.html { add_header Cache-Control "no-cache, no-store, must-revalidate" always; add_header Pragma "no-cache" always; add_header Expires "0" always; } # Vite assets are content-hashed and safe to cache permanently. Missing # chunks must remain a real 404 instead of falling back to index.html. location /assets/ { try_files $uri =404; add_header Cache-Control "public, max-age=31536000, immutable" always; } # Vue Router 的 history 路由刷新时仍返回 index.html。 location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache" always; } }