From 3b65cc47ecf04618d55240c4a64e396d04214550 Mon Sep 17 00:00:00 2001 From: wait4xx Date: Sun, 1 Nov 2026 11:16:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(ops):=20seo-unblock=20v3=20=E8=A1=A5?= =?UTF-8?q?=E2=80=94=E2=80=94=E5=8D=9A=E5=AE=A2=E4=B8=BB=E7=AB=99=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E5=AD=97=E7=AC=A6=E7=B1=BB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v2 残留:([[:space:]];|$) 被解析为空格+分号序列而非字符类,-x 兜底 吃行首缩进——admin location 两轮未落。统一 (^|[[:space:];]) 词边界 并显式排除 git 子域。 验证: bash -n 过;判定正则对 /etc/nginx/sites-enabled/default 实文件 干跑(博客行命中/git 行排除双验) Spec: none (脚本热修 v3 补) Co-authored-by: GLM-5.3 --- scripts/ops/seo-unblock.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/ops/seo-unblock.sh b/scripts/ops/seo-unblock.sh index 455932e..95205e2 100755 --- a/scripts/ops/seo-unblock.sh +++ b/scripts/ops/seo-unblock.sh @@ -20,11 +20,11 @@ for f in "$SITES"/*; do names=$(sudo grep -h "server_name" "$f" 2>/dev/null || true) [ -z "$names" ] && continue # 内部服务判定:server_name 含内部子域且不含主站裸域 - if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then + if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then sudo grep -q "X-Robots-Tag" "$f" || echo " [补回] $f:server 块加 add_header X-Robots-Tag noindex always;" fi # 博客主站判定:server_name 恰含裸域 - if echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then + if echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then sudo grep -q "location /admin/" "$f" || echo " [新增] $f:location /admin/ { noindex }" fi done @@ -41,7 +41,7 @@ sudo sed -i '/X-Robots-Tag noindex/d' "$SNIPPET" && echo " snippet 已剥 noind for f in "$SITES"/*; do names=$(sudo grep -h "server_name" "$f" 2>/dev/null || true) [ -z "$names" ] && continue - if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then + if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then if ! sudo grep -q "X-Robots-Tag" "$f"; then sudo cp "$f" "$BAKDIR/$(basename "$f")" # 在首个 server_name 行后插入(server 块内、顶层指令位置合法) @@ -49,7 +49,7 @@ for f in "$SITES"/*; do echo " 补回:$f" fi fi - if echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then + if echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then if ! sudo grep -q "location /admin/" "$f"; then sudo cp "$f" "$BAKDIR/$(basename "$f")" sudo sed -i "0,/server_name/s/\(server_name.*\)/\1\n location \/admin\/ { add_header X-Robots-Tag noindex always; }/" "$f"