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"