From c84b9fc81ed1967068ae1f09f22650b27536ed34 Mon Sep 17 00:00:00 2001 From: samwaf Date: Fri, 7 Mar 2025 09:18:50 +0800 Subject: [PATCH] fix: healthy host --- waftask/task_health.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/waftask/task_health.go b/waftask/task_health.go index 13a38da..250a493 100644 --- a/waftask/task_health.go +++ b/waftask/task_health.go @@ -114,7 +114,13 @@ func checkBackendHealth(host model.Hosts, ip string, port int, config model.Heal dialer := net.Dialer{ Timeout: time.Duration(config.ResponseTime) * time.Second, } - return dialer.DialContext(ctx, network, fmt.Sprintf("%s:%d", ip, port)) + if host.Remote_ip != "" { + conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(host.Remote_ip, strconv.Itoa(host.Remote_port))) + if err == nil { + return conn, nil + } + } + return dialer.DialContext(ctx, network, addr) }, }, } @@ -129,9 +135,13 @@ func checkBackendHealth(host model.Hosts, ip string, port int, config model.Heal // 添加Host头 if host.IsTransBackDomain == 1 { - req.Host = host.Remote_host - } else { - req.Host = mainHost + // 拆分主机名和端口 + hostPort := strings.Split(host.Remote_host, ":") + if len(hostPort) == 2 { + if req.Host != hostPort[0] { + req.Host = hostPort[0] + } + } } // 打印请求头信息