From 06ce7d6d384ed82ca0ebec9bd4b4173157b949c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 12:17:20 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=A3=E7=A0=81=E5=AE=A1=E6=9F=A5?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=20=E2=80=94=20sed=E6=A8=A1=E5=BC=8F=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E7=A9=BA=E7=99=BD=E3=80=81server=5Fname=E5=8E=BB?= =?UTF-8?q?=E9=87=8D=E6=A3=80=E6=9F=A5=E3=80=81.env.keys=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=81=A5=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/b544c0e1-240b-465e-9194-6ca0e2719deb Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> --- server/proxy/deploy-proxy.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/proxy/deploy-proxy.sh b/server/proxy/deploy-proxy.sh index 3a172df7..4f18131a 100644 --- a/server/proxy/deploy-proxy.sh +++ b/server/proxy/deploy-proxy.sh @@ -254,12 +254,14 @@ configure_nginx() { # 确保主服务器块是default_server (修复localhost/127.0.0.1健康检查匹配问题) if ! grep -q "default_server" "$NGINX_CONF" 2>/dev/null; then - sed -i '0,/listen 80;/{s/listen 80;/listen 80 default_server;/}' "$NGINX_CONF" || true + # 匹配 "listen 80;" 并添加 default_server(兼容不同空白格式) + sed -i '0,/listen[[:space:]]\+80[[:space:]]*;/{s/listen[[:space:]]\+80[[:space:]]*;/listen 80 default_server;/}' "$NGINX_CONF" || true echo " ✅ 已设置为默认服务器 (default_server)" fi # 确保server_name包含localhost (使内部健康检查可匹配) - if ! grep -q "localhost" "$NGINX_CONF" 2>/dev/null; then + # 先检查server_name行中是否已有localhost,避免重复添加 + if ! grep "server_name" "$NGINX_CONF" | head -1 | grep -q "localhost" 2>/dev/null; then sed -i '0,/server_name /{s/server_name /server_name localhost 127.0.0.1 /}' "$NGINX_CONF" || true echo " ✅ 已添加localhost到server_name" fi @@ -330,7 +332,7 @@ health_check() { # 使用ZY_SERVER_HOST作为Host头,确保Nginx server_name匹配 HEALTH_HOST="${ZY_SERVER_HOST:-}" if [ -z "$HEALTH_HOST" ] && [ -f "$PROXY_DIR/.env.keys" ]; then - HEALTH_HOST=$(grep "^ZY_SERVER_HOST=" "$PROXY_DIR/.env.keys" 2>/dev/null | cut -d= -f2-) + HEALTH_HOST=$(grep "^ZY_SERVER_HOST=" "$PROXY_DIR/.env.keys" 2>/dev/null | sed 's/^ZY_SERVER_HOST=//;s/#.*//;s/^[[:space:]]*//;s/[[:space:]]*$//') fi if curl -sf -H "Host: ${HEALTH_HOST:-localhost}" http://127.0.0.1/api/proxy-sub/health >/dev/null 2>&1; then echo " ✅ Nginx反代: 正常 (/api/proxy-sub/ → 3802)"