Skip to content

Commit 188f4fd

Browse files
committed
chore(deploy): keep old next chunks across releases
deploy now merges each build's static assets into a cumulative /var/www/infosphere/static directory and nginx serves /_next/static from it with a fallback to the app server, so pages left open across a deploy keep loading their chunks instead of hitting 404s
1 parent 6706221 commit 188f4fd

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎.github/workflows/deploy.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ jobs:
138138
sudo install -d -m 755 -o www-data -g www-data "$release_dir/web/.next/cache"
139139
sudo chown -R www-data:www-data "$release_dir/web"
140140
141+
# 累积式静态资源目录:chunk 文件名带内容哈希永不冲突,
142+
# 合并而非替换,保证已打开的旧页面引用的旧 chunk 仍然可用
143+
sudo mkdir -p /var/www/infosphere/static
144+
sudo cp -a "$release_dir/web/.next/static/." /var/www/infosphere/static/
145+
141146
# 配置与服务
142147
sudo install -m 600 "$release_dir/infosphere.env" /etc/infosphere/infosphere.env
143148
sudo install -m 644 "$release_dir/infosphere-api.service" /etc/systemd/system/infosphere-api.service

‎deploy/nginx.conf.example‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ server {
3030
proxy_pass http://127.0.0.1:6969;
3131
}
3232

33-
# Next.js 静态资源:长缓存(文件名带哈希)
33+
# Next.js 静态资源:优先读累积式共享目录(跨版本保留旧 chunk,
34+
# 已打开的旧页面不会因部署而 404),缺失时回退到应用服务
3435
location /_next/static/ {
35-
proxy_pass http://127.0.0.1:6900;
36+
alias /var/www/infosphere/static/;
37+
try_files $uri @next_static;
3638
add_header Cache-Control "public, max-age=31536000, immutable";
3739
}
40+
location @next_static {
41+
proxy_pass http://127.0.0.1:6900;
42+
}
3843

3944
# 页面与其他资源:Next.js SSR
4045
location / {

0 commit comments

Comments
 (0)