尝试使用 HAProxy 将请求转发到 ELB 的奇怪行为/错误



我们有一个架构,在多个主机上有多个API。每个 API 都位于 AWS ELB 后面。我们希望在前面放置一个代理,该代理将基于 URI 的请求路由到 ELB。

到目前为止,我所拥有的大部分都有效,但是大约十分之三的请求会导致以下错误(使用 cURL,但问题不在于 cURL):

curl: (35) Unknown SSL protocol error in connection to test-router.versal.com:-9847

我有一种感觉,ELB是罪魁祸首。SSL 在此处终止。

这是我们的HAProxy配置:

global
log 127.0.0.1   local0
log 127.0.0.1   local1 notice
maxconn 10240
user haproxy
group haproxy
daemon
debug
stats socket /var/run/haproxy.sock
log-send-hostname test-router.domain.com
description "HAProxy on test-router.domain.com"
defaults
log     global
mode    http
option  httplog
option  dontlognull
retries 3
option redispatch
option forwardfor
option httpclose
option dontlognull
option tcpka
maxconn 10240
timeout connect 10000ms
timeout client 600000ms
timeout server 600000ms
frontend public
bind *:80
bind *:443
acl elb0 path_beg /elb0
acl elb1 path_beg /elb1
use_backend elb0 if elb0
use_backend elb1 if elb1
bind 0.0.0.0:443 ssl crt /etc/ssl/cert.pem no-sslv3 ciphers AES128+EECDH:AES128+EDH
backend elb0
server server_vcat elb0.domain.com:443 ssl verify none
backend elb1
server server_laapi elb1.domain.com:443 ssl verify none

来自 curl 的 SSL不会在 ELB 处终止。 它终止于 HAProxy,在您的配置中...

bind 0.0.0.0:443 ssl crt /etc/ssl/cert.pem no-sslv3 ciphers AES128+EECDH:AES128+EDH

。然后HAProxy在与ELB的连接上建立一个完全不同的SSL会话:

server ... ssl verify none

在此配置中,ELB 的 SSL 问题不可能通过 HAProxy 传播回 curl。

问题出在您的 HAProxy 配置中,如下所示:

bind *:443

删除该行。这是多余的(并且不正确)。

您告诉 HAProxy 绑定到端口 443 两次:一次说 SSL,一次说 SSL。

因此,从统计上看,在大约 50% 的连接尝试中,curl 发现 HAProxy 没有在端口 443 上说 SSL - 它只是在说 HTTP,而 curl 不能(也不应该)优雅地处理它。

我相信HAProxy没有检测到这种(错误)配置,不是因为实际的错误,而是因为HAProxy内部实现某些东西的方式,与多进程部署和热重载有关,在这种情况下,将HAProxy绑定到同一个套接字是有效的不止一次。

最新更新