From 451947c8d14fb967eba7cba7e4dee9fe493afdce Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Tue, 7 Jul 2026 11:02:21 +0800 Subject: [PATCH] =?UTF-8?q?devops:=20nginx=20=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=20gzip=20+=20/app=20=E5=8D=8F=E5=95=86=E7=BC=93=E5=AD=98=20+?= =?UTF-8?q?=20/shop=20SSR=20=E9=A1=B5=E8=BE=B9=E7=BC=98=E9=97=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o --- deploy/nginx-jiu-ali.conf | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/deploy/nginx-jiu-ali.conf b/deploy/nginx-jiu-ali.conf index 8bd53fc..836f8c8 100644 --- a/deploy/nginx-jiu-ali.conf +++ b/deploy/nginx-jiu-ali.conf @@ -54,6 +54,17 @@ server { 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—— # deploy-site 的 rsync --delete 会清掉站点目录里的挑战文件) location ^~ /.well-known/acme-challenge/ { @@ -115,6 +126,13 @@ server { alias /opt/jiu/web/; index 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 { @@ -125,7 +143,18 @@ server { expires 0; } - # 公开商品详情页(扫码跳转)→ 后端注入 OG 标签(UA 只拦抓取库,不拦空 UA) + # 店铺公开商品列表页 SSR(2026-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/ { if ($jiu_bad_ua_lib) { return 403; } limit_req zone=jiu_pub burst=20 nodelay;