diff --git a/server/admin/ZrAdminNetCore/ZR.Vue/.env.production b/server/admin/ZrAdminNetCore/ZR.Vue/.env.production index 25a6a9e..acbcda5 100644 --- a/server/admin/ZrAdminNetCore/ZR.Vue/.env.production +++ b/server/admin/ZrAdminNetCore/ZR.Vue/.env.production @@ -1,12 +1,10 @@ # 生产环境配置 ENV = 'production' +# 生产环境 — 使用 /api 前缀,由 nginx 反向代理转发到后端 +VITE_APP_API_HOST = '/api' -# 生产环境 -VITE_APP_API_HOST = 'https://admin.api.skzhijia.com' - -VITE_APP_BASE_API = 'https://admin.api.skzhijia.com' - +VITE_APP_BASE_API = '/api' # 路由前缀 VITE_APP_ROUTER_PREFIX = '/' @@ -14,8 +12,8 @@ VITE_APP_ROUTER_PREFIX = '/' # 默认上传地址 VITE_APP_UPLOAD_URL = '/Common/UploadFile' -#socket API -VITE_APP_SOCKET_API = 'https://admin.api.skzhijia.com/msghub' +#socket API — nginx 代理 WebSocket +VITE_APP_SOCKET_API = '/api/msghub' # 是否在打包时开启压缩,支持 gzip 和 brotli VITE_BUILD_COMPRESS = gzip diff --git a/server/admin/ZrAdminNetCore/ZR.Vue/Dockerfile b/server/admin/ZrAdminNetCore/ZR.Vue/Dockerfile index 341d97a..b6f91c0 100644 --- a/server/admin/ZrAdminNetCore/ZR.Vue/Dockerfile +++ b/server/admin/ZrAdminNetCore/ZR.Vue/Dockerfile @@ -23,7 +23,7 @@ FROM 192.168.195.25:19900/library/nginx:alpine # 复制构建产物到nginx目录 COPY --from=builder /app/dist /usr/share/nginx/html -# 复制nginx配置文件 +# 复制nginx配置文件(部署时可替换) COPY nginx.conf /etc/nginx/conf.d/default.conf # 暴露端口 @@ -31,4 +31,3 @@ EXPOSE 80 # 启动nginx CMD ["nginx", "-g", "daemon off;"] - diff --git a/server/admin/ZrAdminNetCore/ZR.Vue/nginx.conf b/server/admin/ZrAdminNetCore/ZR.Vue/nginx.conf index 682483c..70d4d06 100644 --- a/server/admin/ZrAdminNetCore/ZR.Vue/nginx.conf +++ b/server/admin/ZrAdminNetCore/ZR.Vue/nginx.conf @@ -10,6 +10,34 @@ server { gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json; + # ========== 反向代理到后端 API ========== + # 部署时替换此文件,修改 proxy_pass 指向实际后端地址即可 + + # SignalR WebSocket(/api/msghub -> /msghub) + location /api/msghub { + rewrite ^/api/(.*) /$1 break; + proxy_pass http://admin-api:8080; + 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 $scheme; + } + + # 通用 API 代理(/api/xxx -> /xxx) + location /api/ { + rewrite ^/api/(.*) /$1 break; + proxy_pass http://admin-api:8080; + 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; + client_max_body_size 50m; + } + + # ========== 前端静态资源 ========== # 处理Vue Router的history模式 location / { try_files $uri $uri/ /index.html; @@ -29,4 +57,3 @@ server { # 错误页面 error_page 404 /index.html; } -