HAProxy配置HTTPS正向代理出现SSL握手失败、请求无响应问题求助
问题原因
你的配置没有对HTTPS正向代理所需的CONNECT方法做特殊处理,这是配置错误,HAProxy本身支持该场景。
现有配置的核心错误
- 你给
bind配置加了ssl参数,意味着客户端和HAProxy的代理端口先建立TLS连接,之后客户端在加密通道内发送CONNECT请求请求建立到目标站点的隧道,但HAProxy默认不会响应CONNECT请求,也不会自动切换到隧道透传模式,因此客户端一直等待HAProxy返回200 Connection established响应,最终卡住无返回。 - 配置中
http-request set-dst-port hdr(x-port)的逻辑完全错误,标准的CONNECT请求不会携带x-port头,目标端口默认从Host头或CONNECT请求行的目标地址中提取。
正确配置参考
方案1:普通HTTP代理端口(客户端到代理无加密,最常用)
listen forward_https_proxy bind *:5248 # 匹配CONNECT方法 acl is_connect method CONNECT # 处理CONNECT请求,返回200建立隧道 http-request return status 200 if is_connect # 开启HTTP隧道模式,后续流量直接透传不做HTTP解析 option http-tunnel # 解析目标域名,从Host头取域名部分 http-request do-resolve(txn.dstip,mydns) hdr(Host),lower,field(1,:) http-request set-dst var(txn.dstip) # 提取目标端口,默认443 http-request set-dst-port int(443) http-request set-dst-port hdr(Host),field(2,:) if { hdr(Host),field(2,:) -m int } server proxy_https_server * ssl verify none
对应测试请求写法:
requests.get("https://api.ipify.org?format=json", proxies={'https': 'http://myproxy.server:5248'}, verify=False).text
方案2:客户端到代理走TLS加密(即HTTPS代理,你当前的需求场景)
保留bind的ssl配置,其余逻辑和方案1一致:
listen forward_https_proxy bind *:5248 ssl crt /etc/ssl/my.domain.combined.pem acl is_connect method CONNECT http-request return status 200 if is_connect option http-tunnel http-request do-resolve(txn.dstip,mydns) hdr(Host),lower,field(1,:) http-request set-dst var(txn.dstip) http-request set-dst-port int(443) http-request set-dst-port hdr(Host),field(2,:) if { hdr(Host),field(2,:) -m int } server proxy_https_server * ssl verify none
对应测试请求写法:
requests.get("https://api.ipify.org?format=json", proxies={'https': 'https://myproxy.server:5248'}, verify=False).text
内容的提问来源于stack exchange,提问作者knownUnknown
相关产品推荐
相关产品推荐

