This commit is contained in:
dongsk
2026-08-28 16:07:18 +08:00
parent d027eba044
commit cbb5cfd167
2 changed files with 58 additions and 4 deletions
+6 -3
View File
@@ -21,9 +21,12 @@ FROM nginx:alpine
# 将构建产物复制到 Nginx 默认静态目录 # 将构建产物复制到 Nginx 默认静态目录
COPY --from=builder /app/dist /usr/share/nginx/html COPY --from=builder /app/dist /usr/share/nginx/html
# 自定义 Nginx 配置:支持 SPA 路由 fallback + gzip # Nginx 配置模板(支持 envsubst 环境变量替换)
COPY nginx.conf /etc/nginx/conf.d/default.conf 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;"] CMD ["nginx", "-g", "daemon off;"]
+52 -1
View File
@@ -1,5 +1,5 @@
server { server {
listen 80; listen 8901;
server_name localhost; server_name localhost;
root /usr/share/nginx/html; 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_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml;
gzip_min_length 256; 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 # SPA 路由 fallback:所有非文件请求回退到 index.html
location / { location / {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;