server { listen 80; server_name localhost; # 静态资源服务 location / { root /usr/share/nginx/html; index index.html; try_files $uri $uri/ /index.html; } # API 代理到后端 location /api/ { # 注意: 这里使用 Docker Compose 服务名 # 使用 /api/ 后缀确保传递完整路径 proxy_pass http://hxops-backend:5000/api/; 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; # SSE 支持 proxy_buffering off; proxy_cache off; proxy_read_timeout 300s; } }