server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # 1. 生产环境统一由前端容器反代后端 API,前端继续使用相对路径 /api/v1。 # 2. 关闭代理缓冲,避免 Agent SSE 流式响应被 Nginx 缓存后前端长时间收不到数据。 location /api/ { proxy_pass http://api:8080; 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_set_header Connection ""; proxy_buffering off; proxy_cache off; proxy_read_timeout 3600s; add_header X-Accel-Buffering no; } # 1. Vue Router 走 history 模式时,静态资源未命中需要回落到 index.html。 # 2. 这里不负责接口代理,接口统一由上面的 /api location 处理。 location / { try_files $uri $uri/ /index.html; } }