From d1c651e0cdcd6064e7ef7be6e6ee0221afd7a100 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 24 Sep 2026 18:36:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(nginx):=20production=20=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E8=A1=A5=E4=B8=8A=20index.html=20=E7=B2=BE=E7=A1=AE=20no-cache?= =?UTF-8?q?=20=E5=9D=97=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=8F=91=E7=89=88?= =?UTF-8?q?=E5=90=8E=E6=97=A7=20index.html=20=E5=BC=95=E7=94=A8=E8=A2=AB?= =?UTF-8?q?=E5=88=A0=20JS=20=E5=AF=BC=E8=87=B4=E5=8A=A8=E6=80=81=20import?= =?UTF-8?q?=20=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - deploy/configs/nginx-production.conf: 新增 location = /index.html 块(Cache-Control: no-cache, no-store, must-revalidate + Pragma + expires 0) - infra/docker/nginx-production.conf: 同上(Dockerfile 实际使用的配置) - staging 配置此前已有该精确块,无需改动 - 带 hash 的 assets 继续使用 1y + immutable 长缓存 --- deploy/configs/nginx-production.conf | 6 ++++++ infra/docker/nginx-production.conf | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/deploy/configs/nginx-production.conf b/deploy/configs/nginx-production.conf index 1944f8f1f..893f4072d 100644 --- a/deploy/configs/nginx-production.conf +++ b/deploy/configs/nginx-production.conf @@ -12,6 +12,12 @@ server { client_max_body_size 800m; # SPA routing - index.html 禁止缓存,确保每次获取最新版本 + location = /index.html { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + add_header Pragma "no-cache"; + expires 0; + } + location / { try_files $uri /index.html; # HTML 文档(含 try_files 回退的 SPA 路由,如 /login /app/dashboard)一律 no-cache, diff --git a/infra/docker/nginx-production.conf b/infra/docker/nginx-production.conf index c5269f003..93e45515e 100755 --- a/infra/docker/nginx-production.conf +++ b/infra/docker/nginx-production.conf @@ -12,6 +12,13 @@ server { client_max_body_size 800m; + # SPA routing - index.html 禁止缓存,确保每次获取最新版本 + location = /index.html { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + add_header Pragma "no-cache"; + expires 0; + } + # SPA routing - all routes to index.html # 注意:不能加 $uri/,否则 /assets 等与构建产物目录同名的路由会被当成目录访问,返回 403 location / { -- 2.54.0