From c16b643ed8308e2ea9f0da1c4126def6c60a7adb Mon Sep 17 00:00:00 2001 From: OpenBot Date: Tue, 6 Oct 2026 16:17:21 +0800 Subject: [PATCH] chore(scripts): add nginx /agents patch script (idempotent) --- scripts/nginx_agents_patch.sh | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 scripts/nginx_agents_patch.sh diff --git a/scripts/nginx_agents_patch.sh b/scripts/nginx_agents_patch.sh new file mode 100644 index 0000000..c338dd7 --- /dev/null +++ b/scripts/nginx_agents_patch.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# Add /agents reverse proxy to api.vxquant.com site. +# - public map entry so the prefix bypasses the internal-only 404 rule +# - location /agents/ -> 127.0.0.1:30990 (agenthub status http) +# - POST /agents/prompt guarded to internal clients only +# Idempotent: skips if already present. Requires sudo. +set -euo pipefail + +SITE=/etc/nginx/sites-enabled/api.vxquant.com +MARK="# --- agenthub /agents (added by deploy) ---" + +if sudo grep -qF "$MARK" "$SITE"; then + echo "[nginx] /agents already configured; nothing to do" + exit 0 +fi + +# 1) public path map: add /agents before the closing brace of the map block +if ! sudo grep -qE '^\s*~\^/agents\(/\|\$\)' "$SITE"; then + sudo python3 - "$SITE" <<'PY' +import re, sys +path = sys.argv[1] +src = open(path).read() +anchor = " ~^/quantdata(/|$) 1;\n" +assert anchor in src, "map anchor not found" +src = src.replace(anchor, anchor + " ~^/agents(/|$) 1;\n", 1) +open(path, "w").write(src) +print("[nginx] public map: added /agents") +PY +fi + +# 2) location blocks, inserted before the final "location / {" fallback +sudo python3 - "$SITE" "$MARK" <<'PY' +import sys +path, mark = sys.argv[1], sys.argv[2] +src = open(path).read() +block = f""" + {mark} + location /agents/ {{ + proxy_pass http://127.0.0.1:30990/; + proxy_http_version 1.1; + 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; + proxy_read_timeout 300s; + proxy_send_timeout 300s; + client_max_body_size 10m; + }} + location = /agents/prompt {{ + # driving an agent is an operator action: loopback/intranet only + if ($is_internal = 0) {{ return 404; }} + proxy_pass http://127.0.0.1:30990/prompt; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_read_timeout 300s; + client_max_body_size 1m; + }} + # --- end agenthub /agents --- + +""" +anchor = "\n # 其他路径 — 仅内网可访问\n" +assert anchor in src, "fallback anchor not found" +src = src.replace(anchor, block + anchor, 1) +open(path, "w").write(src) +print("[nginx] location blocks: added /agents/ and = /agents/prompt") +PY + +echo "[nginx] testing config" +sudo nginx -t +echo "[nginx] reloading" +sudo systemctl reload nginx +echo "[nginx] done"