server { listen 80; server_name localhost; # 前端静态文件 location / { root /usr/share/nginx/html; index index.html; try_files $uri $uri/ =404; } # 后端API反向代理 location /api/ { proxy_pass http://backend:40001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; 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 $http_x_forwarded_proto; proxy_cache_bypass $http_upgrade; } # 分享链接重定向 location /s/ { proxy_pass http://backend:40001; 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 $http_x_forwarded_proto; } }