SSL终止并转发时,HAProxy SSL roundrobin不起作用

我正在使用以下configuration来终止SSL,以便我可以检查请求,执行URL重写,ACL等,然后将SSLstream量转发回到我的后端服务器。 但是,我不能粘性工作。 当我只使用“mode tcp”并且直接转发tcp路由时,我可以变得粘性工作,但是一旦我开始在前端终止SSL,sticky就停止工作。

这是我的configuration:

frontend https-forward bind *:443 ssl crt /etc/haproxy/certs.d/combo.pem option http-server-close option forwardfor reqadd X-Forwarded-Proto:\ https reqadd X-Forwarded-Port:\ 443 capture request header Referrer len 64 capture request header Content-Length len 10 capture request header User-Agent len 64 # set HTTP Strict Transport Security (HTST) header rspadd Strict-Transport-Security:\ max-age=15768000 # some ACLs and URL rewrites... default_backend backstuff backend backstuff log 127.0.0.1 local2 notice balance roundrobin option ssl-hello-chk stick-table type binary len 32 size 30k expire 30m acl clienthello req_ssl_hello_type 1 acl serverhello rep_ssl_hello_type 2 tcp-request inspect-delay 5s tcp-request content accept if clienthello tcp-response content accept if serverhello stick on payload_lv(43,1) if clienthello stick store-response payload_lv(43,1) if serverhello server PO1 10.35.59.160:443 ssl verify none maxconn 5000 server PO2 10.35.59.161:443 ssl verify none maxconn 5000 

当你使用mode http (默认除非你明确地指定了mode tcp )的时候,你不能坚持使用SSL Session ID的原因是你试图在数据包的有效负载的某些字节上执行它,已经被解码,这些偏移可能包含完全随机的数据。

你有两个select。

  1. 坚持基于源IP

    如果你不反对坚持客户端的IP,而不是像你现在正在做的SSL会话ID,那么你可以改变你的configuration看起来像这样:

     frontend https-forward bind *:443 ssl crt /etc/haproxy/certs.d/combo.pem mode http option http-server-close option forwardfor reqadd X-Forwarded-Proto:\ https reqadd X-Forwarded-Port:\ 443 capture request header Referrer len 64 capture request header Content-Length len 10 capture request header User-Agent len 64 # set HTTP Strict Transport Security (HTST) header rspadd Strict-Transport-Security:\ max-age=15768000 # some ACLs and URL rewrites... default_backend backstuff backend backstuff mode http log 127.0.0.1 local2 notice balance roundrobin option ssl-hello-chk stick-table type ip size 30k expire 30m stick on src server PO1 10.35.59.160:443 ssl verify none maxconn 5000 server PO2 10.35.59.161:443 ssl verify none maxconn 5000 

    关键的变化是stick-tablestick on在线,以及明确使用mode http

    正如你所说,如果许多访问你的网站的客户端在NAT后面,他们将最终在同一台服务器上,所以它不是最stream畅的发布,但它工作并提供你想要的function。

  2. 使用HAProxy解码的SSL会话ID

    在这里你必须通过ssl_fc_session_id ( docs )来利用HAproxy的连接知识。

    ssl_fc_session_id :二进制
    当传入连接通过SSL / TLS传输层进行时,返回前端连接的SSL ID。 将给定的客户端粘贴到服务器是有用的。 需要注意的是,有些浏览器每隔几分钟刷新一次会话ID。

    在这种情况下,您将使用与上面提供的configuration相同的configuration,但是stick-tablestick线会更改为:

      stick-table type binary len 32 size 30k expire 30m stick on ssl_fc_session_id 

    这实际上最类似于你想要达到的目标。