使用HAProxy实施TCP粘性会话以处理SSL传递stream量

当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议:

  1. 在HAProxy 1.5终止SSL – 在我的情况下是不可能的。 SSL需要由后端服务器来处理。
  2. 使用SSL会话ID来保持粘性。 – 我很怀疑要试一下,因为我还不太明白。 它似乎是使用haproxy的修改版(?)版本。
  3. 使用send-proxy指令和X-Forward-Proto 。 – 但意识到这也需要一个仅HTTP的后端。

将不胜感激任何意见。

最简单的解决scheme是使用balance source ,但是如果很多客户端来自同一个IP,那么在后端服务器上可能不太公平。

请参阅http://blog.haproxy.com/2013/04/22/client-ip-persistence-or-source-ip-hash-load-balancing/了解更多有关完成此操作的方法的讨论。

如果问题的根源在于后端服务器期望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,如何。