From cbb5cfd167432ccb8ce2289e0487f000c7b5d69a Mon Sep 17 00:00:00 2001 From: dongsk Date: Fri, 28 Aug 2026 16:07:18 +0800 Subject: [PATCH] update --- Dockerfile | 9 ++++++--- nginx.conf | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed5bcb9..affb8a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,9 +21,12 @@ FROM nginx:alpine # 将构建产物复制到 Nginx 默认静态目录 COPY --from=builder /app/dist /usr/share/nginx/html -# 自定义 Nginx 配置:支持 SPA 路由 fallback + gzip -COPY nginx.conf /etc/nginx/conf.d/default.conf +# Nginx 配置模板(支持 envsubst 环境变量替换) +COPY nginx.conf /etc/nginx/templates/default.conf.template -EXPOSE 80 +# 默认后端 API 地址(运行时可通过 -e BACKEND_URL=... 覆盖) +ENV BACKEND_URL=http://host.docker.internal:8000 + +EXPOSE 8901 CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf index 037a0b8..c00a01b 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,5 +1,5 @@ server { - listen 80; + listen 8901; server_name localhost; root /usr/share/nginx/html; @@ -10,6 +10,57 @@ server { gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml; gzip_min_length 256; + # 后端 API 反向代理(支持 SSE 长连接) + location /api/v1/ { + proxy_pass ${BACKEND_URL}/api/v1/; + 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; + proxy_http_version 1.1; + proxy_set_header Connection ""; + + # 禁止浏览器缓存 API 响应 + add_header Cache-Control "no-cache, no-store, must-revalidate" always; + add_header Pragma "no-cache" always; + } + + # 健康检查 + location /health { + proxy_pass ${BACKEND_URL}/health; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + # Bexell 排程 API 反向代理 + location /bexapi/ { + proxy_pass https://bexell-scheduling.dongsk.top/api/; + proxy_set_header Host bexell-scheduling.dongsk.top; + 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_ssl_server_name on; + } + + # 鼎捷云 IAM 登录服务反向代理(与 vite.config.ts 中 /iam-api 代理一致) + location /iam-api/ { + proxy_pass https://iam.digiwincloud.com.cn/; + proxy_set_header Host iam.digiwincloud.com.cn; + 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_ssl_server_name on; + + # 禁止浏览器缓存 API 响应 + add_header Cache-Control "no-cache, no-store, must-revalidate" always; + add_header Pragma "no-cache" always; + } + # SPA 路由 fallback:所有非文件请求回退到 index.html location / { try_files $uri $uri/ /index.html;