From 1c04ff0d7bc9ece99539acda41ab1788ec3970fb Mon Sep 17 00:00:00 2001 From: lzh Date: Thu, 18 Dec 2025 13:57:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E8=B7=A8=E5=9F=9F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/.env.production | 13 ++++++------- apps/web-antd/nginx.conf | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/web-antd/.env.production b/apps/web-antd/.env.production index 8b0b6fab5..42611909d 100644 --- a/apps/web-antd/.env.production +++ b/apps/web-antd/.env.production @@ -1,20 +1,19 @@ VITE_BASE=/ # 请求路径 -VITE_BASE_URL=http://172.17.16.14:48080 +VITE_BASE_URL=/admin-api # 接口地址 -VITE_GLOB_API_URL=http://172.17.16.14:48080/admin-api -# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务 +VITE_GLOB_API_URL=/admin-api +# 文件上传类型:server - 后端上传?client - 前端直连上传,仅支持S3服务 VITE_UPLOAD_TYPE=server -# 是否开启压缩,可以设置为 none, brotli, gzip +# 是否开启压缩,可以设置?none, brotli, gzip VITE_COMPRESS=none -# 是否开启 PWA +# 是否开?PWA VITE_PWA=false -# vue-router 的模式 -VITE_ROUTER_HISTORY=hash +# vue-router 的模?VITE_ROUTER_HISTORY=hash # 是否注入全局loading VITE_INJECT_APP_LOADING=true diff --git a/apps/web-antd/nginx.conf b/apps/web-antd/nginx.conf index 0e547526d..f69f51244 100644 --- a/apps/web-antd/nginx.conf +++ b/apps/web-antd/nginx.conf @@ -13,6 +13,27 @@ server { root /usr/share/nginx/html; index index.html; + # API 反向代理到后端服务 + # 如果后端在 Docker 容器中,使用容器名:http://aiot-server:48080 + # 如果后端在宿主机上,使用内网地址:http://172.17.16.14:48080 或 http://172.17.0.1:48080 + location /admin-api { + proxy_pass http://172.17.16.14:48080/admin-api; + 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; + + # 解决跨域问题 + add_header Access-Control-Allow-Origin * always; + add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS' always; + add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always; + + # 处理 OPTIONS 预检请求 + if ($request_method = 'OPTIONS') { + return 204; + } + } + # 解决 SPA 路由刷新 404 问题 location / { try_files $uri $uri/ /index.html;