When load balancing HTTPS, we can’t have access to HTTP protocol since everything is encrypted. So it’s hard to maintain connection persistence in such condition.

ALOHA load balancer allows you to maintain HTTPS sessions based on SSL connection ID.
That way, even if you can’t see the protocol, you can maintain affinity between a user and a backend

This is much better than doing affinity by IP source, since a lot of users could share the same IP address and generate an extra load on one backend.
Furthermore, we can follow on session even if the client change its IP address.


The configuration below explains how you can maintain session on SSL ID and store it in a stick-table.
We take advantage of HAProxy ACLs to do protocol validation.

# Learn SSL session ID from both request and response and create affinity.
backend https
	mode tcp
	balance roundrobin

	# maximum SSL session ID length is 32 bytes.
	stick-table type binary len 32 size 30k expire 30m

	acl clienthello req_ssl_hello_type 1
	acl serverhello rep_ssl_hello_type 2

	# use tcp content accepts to detects ssl client and server hello.
	tcp-request inspect-delay 5s
	tcp-request content accept if clienthello

	# no timeout on response inspect delay by default.
	tcp-response content accept if serverhello

	# SSL session ID (SSLID) may be present on a client or server hello.
	# Its length is coded on 1 byte at offset 43 and its value starts
	# at offset 44.
	# Match and learn on request if client hello.
	stick on payload_lv(43,1) if clienthello

	# Learn on response if server hello.
	stick store-response payload_lv(43,1) if serverhello

	server s1
	server s2