devops: nginx 运行时 gzip + /app 协商缓存 + /shop SSR 页边缘闸

- gzip on(js/wasm/json/css,图片刻意不压):Web 版首包 12.5MB → ~4.4MB
- /app/ 加 Cache-Control no-cache(etag 304 协商,产物无 hash 不做长缓存)
- 新增 /shop/ location:与 shops API 同参数(jiu_shoplist 2r/s + UA 拦截 + limit_conn 10)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
This commit is contained in:
wangjia
2026-07-07 11:02:21 +08:00
parent 9ea38a9b56
commit 451947c8d1
+30 -1
View File
@@ -54,6 +54,17 @@ server {
client_max_body_size 20m; client_max_body_size 20m;
# 传输压缩(2026-07-07 公开页提速方案 A′):运行时 gzip,覆盖 Flutter Web 静态
# 大文件(main.dart.js 5.3MB→~1.3MB、canvaskit.wasm 7.2MB→~3MB)与反代 JSON。
# 图片(JPEG/PNG)刻意不在列——本身已是压缩格式,上传侧另有 1200px+q85 压缩。
gzip on;
gzip_comp_level 5;
gzip_min_length 1k;
gzip_vary on;
gzip_proxied any;
gzip_types application/javascript application/wasm application/json
text/css text/plain image/svg+xml application/octet-stream;
# certbot HTTP-01 续期通道(webroot 独立目录,不放 marketing—— # certbot HTTP-01 续期通道(webroot 独立目录,不放 marketing——
# deploy-site 的 rsync --delete 会清掉站点目录里的挑战文件) # deploy-site 的 rsync --delete 会清掉站点目录里的挑战文件)
location ^~ /.well-known/acme-challenge/ { location ^~ /.well-known/acme-challenge/ {
@@ -115,6 +126,13 @@ server {
alias /opt/jiu/web/; alias /opt/jiu/web/;
index index.html; index index.html;
try_files $uri $uri/ /app/index.html; try_files $uri $uri/ /app/index.html;
# 协商缓存(2026-07-07 方案 A′):Flutter 产物文件名无 hash,长缓存会在发版后
# 新旧错配白屏,故走 etag 304——复访零字节,首访靠上面的 gzip。
# 注意 add_header 覆盖继承:补回 server 级安全头。
add_header Cache-Control "no-cache";
add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Frame-Options SAMEORIGIN always;
add_header X-Content-Type-Options nosniff always;
} }
location = /app/index.html { location = /app/index.html {
@@ -125,7 +143,18 @@ server {
expires 0; expires 0;
} }
# 公开商品详情页(扫码跳转)→ 后端注入 OG 标签(UA 只拦抓取库,不拦空 UA) # 店铺公开商品列表页 SSR2026-07-07 新增短链):与 shops API 同一套边缘闸
location ~ ^/shop/ {
if ($jiu_bad_ua_lib) { return 403; }
limit_req zone=jiu_shoplist burst=5 nodelay;
limit_conn jiu_conn 10;
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 30s;
}
# 公开商品详情页(扫码跳转)→ 后端 SSR 轻量页(UA 只拦抓取库,不拦空 UA)
location ~ ^/product/ { location ~ ^/product/ {
if ($jiu_bad_ua_lib) { return 403; } if ($jiu_bad_ua_lib) { return 403; }
limit_req zone=jiu_pub burst=20 nodelay; limit_req zone=jiu_pub burst=20 nodelay;