server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # API 代理到 Gateway location /api/ { proxy_pass http://gateway:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # HTML 文件禁用缓存 location ~* \.html$ { add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; try_files $uri $uri/ /index.html; } # 静态资源 location / { try_files $uri $uri/ /index.html; } # 缓存静态资源(JS/CSS/图片等) location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1d; add_header Cache-Control "public, immutable"; } }