# 本文件由官方 Nginx 镜像在启动时替换四个环境变量,生成 conf.d/default.conf。 # 保留 Nginx 自身变量,不能直接对整个文件执行无变量白名单的 envsubst。 map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; client_max_body_size 100m; # API 前缀与构建时 VITE_APP_BASE_API 一致;转发时剥离该前缀。 location = ${API_PREFIX} { return 308 ${API_PREFIX}/$is_args$args; } location ${API_PREFIX}/ { proxy_pass ${API_UPSTREAM}/; proxy_http_version 1.1; proxy_set_header Host $proxy_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-Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Connection ""; proxy_ssl_server_name on; proxy_read_timeout 300s; } # WebSocket 保留原请求路径与查询参数,兼容 /ws 以及 /ws/ 下的端点。 location ~ ^${WS_PATH}(/|$) { proxy_pass ${WS_UPSTREAM}; proxy_http_version 1.1; proxy_set_header Host $proxy_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-Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_ssl_server_name on; proxy_read_timeout 3600s; proxy_send_timeout 3600s; proxy_buffering off; } location = /index.html { add_header Cache-Control "no-cache"; } # history 路由刷新时回退到应用入口,由 Vue Router 解析页面。 location / { try_files $uri $uri/ /index.html; } }