From 8f0056c9b227d2735b1f71a8aff3e8032b3a7a3d Mon Sep 17 00:00:00 2001 From: zpc Date: Tue, 24 Mar 2026 18:01:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20admin=E5=89=8D=E7=AB=AF=E6=94=B9?= =?UTF-8?q?=E7=94=A8nginx=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86=EF=BC=8CAPI?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E9=83=A8=E7=BD=B2=E6=97=B6=E5=8F=AF=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZrAdminNetCore/ZR.Vue/.env.production | 12 ++++---- server/admin/ZrAdminNetCore/ZR.Vue/Dockerfile | 3 +- server/admin/ZrAdminNetCore/ZR.Vue/nginx.conf | 29 ++++++++++++++++++- 3 files changed, 34 insertions(+), 10 deletions(-) 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; } -