#!/bin/bash # 回滚脚本(launch.sh 的逆操作):静态 root 切回 Halo proxy_pass(18090)。秒级。 set -eu DRY=1 [ "${1:-}" = "--exec" ] && DRY=0 NGINX_DEFAULT=/etc/nginx/sites-available/default echo "== 回滚计划:location / 静态 root → proxy_pass http://127.0.0.1:18090 ==" if [ $DRY = 1 ]; then echo "== DRY-RUN(--exec + root 才执行) =="; exit 0; fi if [ "$(id -u)" != 0 ]; then echo "须 root:sudo bash $0 --exec" >&2; exit 1; fi grep -q "docker_apps/blog/www-staging" "$NGINX_DEFAULT" || { echo "未找到静态 root,无需回滚或已回滚"; exit 0; } python3 - "$NGINX_DEFAULT" <<'PY' import re, sys path = sys.argv[1] s = open(path, encoding="utf-8").read() s2 = re.sub( r"location / \{\n root /home/wait4x/docker_apps/blog/www-staging;\n try_files \$uri \$uri/index\.html =404;\n \}", """location / { proxy_pass http://127.0.0.1:18090; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }""", s, count=1) assert s2 != s, "静态块未匹配,人工核对" open(path, "w", encoding="utf-8").write(s2) print("reverted: location / -> halo 18090") PY nginx -t && systemctl reload nginx && echo "ROLLED BACK:wait4x.online 已回 Halo"