From d50711282995414992fe18e20ee083ac90b06cac Mon Sep 17 00:00:00 2001 From: 2910410219 <2910410219@qq.com> Date: Fri, 22 May 2026 13:34:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Nginx=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BB=A5=E6=94=AF=E6=8C=81=E6=96=B0=E7=9A=84=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E5=92=8C=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E7=AB=AF?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改根路径重定向至网页端的 index.html。 - 新增网页端和后台管理端的路径配置,确保静态资源正确加载。 - 优化了静态文件查找和代理逻辑,提升了请求处理效率。 --- ngnix.conf | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/ngnix.conf b/ngnix.conf index 65a8762..b9857ce 100644 --- a/ngnix.conf +++ b/ngnix.conf @@ -1,20 +1,8 @@ # Nginx 静态文件服务 + 智能代理 server { - # 静态资源根目录 + # 静态资源根目录(dist) root /usr/share/nginx/html; - - # 前端资源路径别名(/sys/ -> /) - location /sys/ { - alias /usr/share/nginx/html/; - try_files $uri $uri/ =404; - } - - # 根路径固定进入前端,避免落到后端登录页 - location = / { - return 302 /sys/; - } - index index.html; # SSL 配置 @@ -24,6 +12,23 @@ server { ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; + # 根路径默认进入网页端 + location = / { + return 302 /web/index.html; + } + + # 网页端(public/web/index.html -> dist/web/index.html) + location /web/ { + alias /usr/share/nginx/html/web/; + try_files $uri $uri/ /web/index.html; + } + + # 后台管理端(dist/index.html,前缀 /sys/) + location /sys/ { + alias /usr/share/nginx/html/; + try_files $uri $uri/ /sys/index.html; + } + # 1. 先尝试作为静态文件查找 location / { try_files $uri $uri/ @proxy; @@ -31,12 +36,12 @@ server { # 2. 无法找到的请求(API路径)代理到后端 location @proxy { - # 判断URI最后一段是否有扩展名 - # 有扩展名返回404,无扩展名则代理 + # 判断 URI 最后一段是否有扩展名 + # 有扩展名返回 404,无扩展名则代理 if ($uri ~ \.[^./]+$) { return 404; } - + proxy_pass http://116.204.74.41:8000; proxy_http_version 1.1; proxy_set_header Host $host;