server {
  listen 80;
  server_name _;
  root /usr/share/nginx/html;
  index index.html;

  # 反代 API + SSE 兼容
  location /api/ {
    proxy_pass http://server:4001;
    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_buffering off;
    proxy_cache off;
    proxy_read_timeout 600s;
    chunked_transfer_encoding on;
    # SSE 不要被压缩
    proxy_set_header Accept-Encoding "identity";
  }

  # SPA history fallback
  location / {
    try_files $uri $uri/ /index.html;
  }

  # 静态资源缓存
  location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
    expires 7d;
    add_header Cache-Control "public, max-age=604800";
  }
}
