From 73f23927d9874a85687596e0ca1d29448467cbaa Mon Sep 17 00:00:00 2001 From: HomeDash Bot Date: Fri, 11 Sep 2026 17:03:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(nginx):=20/admin=20=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91=EF=BC=8C=E6=94=B9=E7=94=A8=E7=B2=BE?= =?UTF-8?q?=E7=A1=AE=E5=8F=8D=E4=BB=A3=E7=9B=B4=E6=8E=A5=20200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一版把 /admin 改成相对 301,但 301 会被浏览器**永久缓存**,用户即使 服务端已修好仍被旧的 http://<域名>:8080/admin/ 带走。现在精确匹配 location = /admin 直接反代(无 Location 头),并加 Cache-Control: no-store, 彻底消除这条跳转。其余前缀改 302(不被永久记住),/extension 直接给安装页。 --- nginx.conf | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/nginx.conf b/nginx.conf index e3b3149..c442242 100644 --- a/nginx.conf +++ b/nginx.conf @@ -69,16 +69,24 @@ http { # Admin WebUI(内部 3005) # - # 必须显式处理不带尾斜杠的 /admin:否则它会落到 `location /` 的 - # try_files $uri/ 分支,nginx 自动补斜杠时按 $host:$server_port 拼出 - # 绝对地址,于是公网被跳到 http://<域名>:8080/admin/(容器内部端口泄漏)。 - # 这里返回相对地址,浏览器沿用当前的协议/主机/端口。 + # 不带尾斜杠的 /admin 必须**直接返回页面**,不能靠重定向: + # 1) 它会落到 `location /` 的 try_files $uri/ 分支,nginx 自动补斜杠时按 + # $host:$server_port 拼绝对地址,把内部端口 8080 泄到公网; + # 2) 即便改成相对重定向,301 会被浏览器**永久缓存**,用户改好后仍被旧跳转带走。 + # 所以这里精确匹配并直接反代(尾斜杠由 proxy_pass 的 / 吸收)。 location = /admin { - return 301 /admin/; + proxy_pass http://127.0.0.1:3005/; + # 管理页不缓存:避免旧的跳转/旧页面被浏览器长期记住 + add_header Cache-Control "no-store" always; + 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; } location /admin/ { proxy_pass http://127.0.0.1:3005/; + add_header Cache-Control "no-store" always; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -98,8 +106,9 @@ http { } # item-icons 从 data volume 提供 + # 用 302(不是 301):这两个目录不需要浏览器永久记住跳转。 location = /item-icons { - return 301 /item-icons/; + return 302 /item-icons/; } location /item-icons/ { @@ -108,7 +117,7 @@ http { # 自定义壁纸(后台「外观」上传,目录也在 data 卷) location = /wallpapers { - return 301 /wallpapers/; + return 302 /wallpapers/; } location /wallpapers/ { @@ -116,9 +125,13 @@ http { add_header Cache-Control "public, max-age=31536000, immutable"; } - # 浏览器扩展安装包目录 + # 浏览器扩展安装目录:/extension 和 /extension/ 都直接给安装页,不靠重定向 location = /extension { - return 301 /extension/; + rewrite ^ /extension/install.html last; + } + + location = /extension/ { + rewrite ^ /extension/install.html last; } # Dashy SPA 路由兜底