fix(nginx): production 补 index.html no-cache 精确块,防旧缓存导致动态 import 失败 #2031

Merged
auto-approve-bot merged 1 commits from fix/nginx-index-nocache into develop 2026-09-24 18:47:55 +08:00
Owner

问题

发版后浏览器缓存旧 index.html,引用已被删除的带 hash 的 JS chunk,导致动态 import 失败、页面白屏/报错。

改动

给 production nginx 配置补上精确匹配 /index.html 的 no-cache 头块(staging 配置此前已有):

location = /index.html {
    add_header Cache-Control "no-cache, no-store, must-revalidate";
    add_header Pragma "no-cache";
    expires 0;
}
  • deploy/configs/nginx-production.conf:补精确块(放在 location / 之前,优先匹配)
  • infra/docker/nginx-production.conf:同上(Dockerfile 实际 COPY 到容器使用的配置)
  • deploy/configs/nginx-staging.conf 和 infra/docker/nginx-staging.conf:此前已存在该精确块,无需改动
  • 带 hash 的 /assets/*.js、*.css、图片字体等继续由 expires 1y + immutable 长缓存,不受影响

效果

  • 浏览器访问 https://域名/index.html 时强制不缓存,每次请求都拿最新版本(ETag/Last-Modified 协商)
  • Vite 构建产物带 hash,文件内容变 hash 就变,assets 长缓存依然安全
  • 已经缓存了旧 index.html 的用户需要硬刷(Ctrl+Shift+R)一次,之后不再出现该问题

验证

  • 本地 nginx -t 语法检查通过(待镜像构建后自动验证)
  • staging 配置此前已生效,本次改动对齐 production
## 问题 发版后浏览器缓存旧 index.html,引用已被删除的带 hash 的 JS chunk,导致动态 import 失败、页面白屏/报错。 ## 改动 给 production nginx 配置补上精确匹配 `/index.html` 的 no-cache 头块(staging 配置此前已有): ```nginx location = /index.html { add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; expires 0; } ``` - `deploy/configs/nginx-production.conf`:补精确块(放在 location / 之前,优先匹配) - `infra/docker/nginx-production.conf`:同上(Dockerfile 实际 COPY 到容器使用的配置) - `deploy/configs/nginx-staging.conf` 和 `infra/docker/nginx-staging.conf`:此前已存在该精确块,无需改动 - 带 hash 的 `/assets/*.js`、`*.css`、图片字体等继续由 `expires 1y + immutable` 长缓存,不受影响 ## 效果 - 浏览器访问 `https://域名/index.html` 时强制不缓存,每次请求都拿最新版本(ETag/Last-Modified 协商) - Vite 构建产物带 hash,文件内容变 hash 就变,assets 长缓存依然安全 - 已经缓存了旧 index.html 的用户需要硬刷(Ctrl+Shift+R)一次,之后不再出现该问题 ## 验证 - 本地 `nginx -t` 语法检查通过(待镜像构建后自动验证) - staging 配置此前已生效,本次改动对齐 production
xiaoxia added 1 commit 2026-09-24 18:36:54 +08:00
fix(nginx): production 环境补上 index.html 精确 no-cache 块,解决发版后旧 index.html 引用被删 JS 导致动态 import 失败
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m45s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m0s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m57s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 3m29s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 4m39s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 4m41s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 5m27s
AI Code Review / AI Code Review (pull_request) Successful in 6m34s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 7m40s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 10m16s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 1s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 7m59s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 27s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 36s
d1c651e0cd
- 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 长缓存

🚀 预览环境已部署

项目 详情
PR号 #2031
预览链接 https://pr-2031.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #2031 | | 预览链接 | [https://pr-2031.preview.xiaoxiajianji.com](https://pr-2031.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot merged commit a998ccd527 into develop 2026-09-24 18:47:55 +08:00
auto-approve-bot deleted branch fix/nginx-index-nocache 2026-09-24 18:47:57 +08:00

🗑️ 预览环境已清理

PR #2031 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #2031 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.