当SSL必须在后端服务器上终止时,我们如何在HAProxy中实现会话粘性? 我们需要粘性,因为后端不能共享会话。
这是我的原始configuration:
# SSL passthrough listen https_handler bind 1.2.3.4:443 mode tcp balance leastconn stick match src stick-table type ip size 200k expire 30m server s1 1.1.1.1:443 server s2 1.1.1.2:443 # haproxy logs (not sticking) 10.xx2:xxxxx [17/Dec/2014:19:29:41.396] fe BACKEND_Website/s1 37/0/1/3/41 200 8364 10.xx2:xxxxx [17/Dec/2014:19:29:41.456] fe BACKEND_Website/s1 36/0/1/1/39 200 9082 10.xx2:xxxxx [17/Dec/2014:19:29:41.456] fe BACKEND_Website/s2 35/0/1/3/39 200 2529 10.xx2:xxxxx [17/Dec/2014:19:29:41.545] fe BACKEND_Website/s1 35/0/0/3/38 200 1460 10.xx2:xxxxx [17/Dec/2014:19:29:41.501] fe BACKEND_Website/s2 36/0/1/1/109 200 376 10.xx2:xxxxx [17/Dec/2014:19:29:41.545] fe BACKEND_Website/s1 36/0/1/1/74 200 2298 10.xx2:xxxxx [17/Dec/2014:19:29:41.604] fe BACKEND_Website/s1 35/0/1/2/38 200 5542
下面的configuration是我尝试读取src :
这会导致502错误网关错误。 我认为,这是因为stream量到达后端时已经被解密了。
# terminate SSL at HAProxy listen https_handler bind 1.2.3.4:443 ssl crt /etc/ssl/certs/certs.pem mode tcp balance leastconn stick match src stick-table type ip size 200k expire 30m server s1 1.1.1.1:443 server s2 1.1.1.2:443
请注意,我将证书插入绑定。 这是为了HAProxy能够读取src并设置stick-table。 (不知道这是否正确。)在这一点上,stream量已经解密。
我认为这个问题在于,当这个解密的stream量被传递到后端服务器,这期望encryptionstream量…
我看到了这些build议:
send-proxy指令和X-Forward-Proto头 。 – 但意识到这也需要一个仅HTTP的后端。 将不胜感激任何意见。
最简单的解决scheme是使用balance source ,但是如果很多客户端来自同一个IP,那么在后端服务器上可能不太公平。
如果问题的根源在于后端服务器期望stream量是HTTPS而不是HTTP,请尝试对HTTP进行encryption并执行常规的Layer7负载平衡。
listen https_handler bind 1.2.3.4:443 ssl crt /etc/ssl/certs/certs.pem mode http balance leastconn # any stick rules you need server s1 1.1.1.1:443 ssl server s2 1.1.1.2:443 ssl
更容易 – 但你显然试图坚持src ,为什么你甚至解密的TCPstream量呢?
listen https bind 1.2.3.4:443 # <- NO ssl setting mode tcp balance leastconn stick match src stick-table type ip size 200k expire 30m server s1 1.1.1.1:443 ssl server s2 1.1.1.2:443 ssl
在TCP模式下,您不关心有效载荷。 具体来说,你不关心它是否encryption,如何。