IMPORTANT NOTE: this article has been outdated since HAProxy-1.5-dev12 has been released (10th of September). For more information about SSL inside HAProxy. please read:
How to get SSL with HAProxy getting rid of stunnel, stud, nginx or pound
Synopsis
Since yesterday night (FR time), HAProxy can support SSL offloading. It can even crypt traffic to a downstream server.
We’ll see later all the fun we could have with these nice features and the goodness it could bring in term of architecture. Today, I’ll just focus on how to install and configure HAProxy to offload SSL processing from your servers.
It’s important to notice that in order to be able to manage SSL connections, a huge rework of connection management has been done in HAProxy. Despite the long time spent on testing, there might still remain some bugs.
So we ask anybody who tests the procedure below to report bugs to HAProxy mailing list.
Note as well that the job was done by Exceliance engineers, who already improved stunnel and stud.
SSL offloading diagram
This is pretty simple, as shown on the picture below. The client will get connected on HAProxy using SSL, HAProxy will process SSL and get connected in clear to the server:

HAproxy installation
cd /usr/src wget http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120905.tar.gz tar xzf haproxy-ss-20120905.tar.gz cd haproxy-ss-20120905/ make TARGET=linux2628 USE_STATIC_PCRE=1 USE_OPENSSL=1 sudo make PREFIX=/opt/haproxy-ssl install
HAProxy configuration for SSL offloading
First of all, you have to generate a key and a certificate using openssl and concatenate them in a file, the certificate first, then the key.
Here is mine, just copy/paste it in a file for your tests:
-----BEGIN CERTIFICATE----- MIIBrzCCARgCCQCfMsCGwq31yzANBgkqhkiG9w0BAQUFADAcMRowGAYDVQQDExF3 d3cuZXhjZWxpYW5jZS5mcjAeFw0xMjA5MDQwODU3MzNaFw0xMzA5MDQwODU3MzNa MBwxGjAYBgNVBAMTEXd3dy5leGNlbGlhbmNlLmZyMIGfMA0GCSqGSIb3DQEBAQUA A4GNADCBiQKBgQDFxSTUwX5RD4AL2Ya5t5PAaNjcwPa3Km40uaPKSHlU8AMydxC1 wB4L0k3Ms9uh98R+kIJS+TxdfDaYxk/GdDYI1CMm4TM+BLHGAVA2DeNf2hBhBRKb TAgxCxXwORJQSB/B+1r0/ZiQ2ig5Jzr8xGHz+tBsHYZ+t+R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w== -----END RSA PRIVATE KEY-----
Now, HAProxy configuration, very basic, for test purpose, and just to let you know which lines are very important:
frontend ft_test mode http bind 0.0.0.0:8443 ssl crt ./haproxy.pem # basic conf require only 1 keyword # other (self described) options are: [ciphers <suite>] [nosslv3] [notlsv1] default_backend bk_test backend bk_test mode http server srv1 127.0.0.1:80
Running HAProxy
First, just test the configuration is valid:
/opt/haproxy-ssl/sbin/haproxy -c -f ./ha.cfg [WARNING] 247/110924 (6497) : config : missing timeouts for frontend 'ft_test'. | While not properly invalid, you will certainly encounter various problems | with such a configuration. To fix this, please ensure that all following | timeouts are set to a non-zero value: 'client', 'connect', 'server'. [WARNING] 247/110924 (6497) : config : missing timeouts for backend 'bk_test'. | While not properly invalid, you will certainly encounter various problems | with such a configuration. To fix this, please ensure that all following | timeouts are set to a non-zero value: 'client', 'connect', 'server'. Configuration file is valid
Don’t worry about warnings, I purposely wrote a very basic configuration.
Now, you can run HAProxy:
/opt/haproxy-ssl/sbin/haproxy -f ./ha.cfg
Testing SSL provided by HAProxy
Use curl, with “–insecure” option if your certificate is self-signed, like mine:
curl --noproxy \* -D - --insecure https://127.0.0.1:8443/index.html HTTP/1.1 200 OK Date: Tue, 04 Sep 2012 09:13:55 GMT Server: Apache/2.2.16 (Debian) Last-Modified: Tue, 04 Sep 2012 09:10:01 GMT ETag: "a35d1-e-4c8dc9f7d6c40" Accept-Ranges: bytes Content-Length: 14 Vary: Accept-Encoding Content-Type: text/html Welcome page.
Check SSL parameters with openssl in client mode:
openssl s_client -connect 127.0.0.1:8443
CONNECTED(00000003)
depth=0 /CN=www.exceliance.fr
verify error:num=18:self signed certificate
verify return:1
depth=0 /CN=www.exceliance.fr
verify return:1
---
Certificate chain
0 s:/CN=www.exceliance.fr
i:/CN=www.exceliance.fr
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIBrzCCARgCCQCfMsCGwq31yzANBgkqhkiG9w0BAQUFADAcMRowGAYDVQQDExF3
d3cuZXhjZWxpYW5jZS5mcjAeFw0xMjA5MDQwODU3MzNaFw0xMzA5MDQwODU3MzNa
MBwxGjAYBgNVBAMTEXd3dy5leGNlbGlhbmNlLmZyMIGfMA0GCSqGSIb3DQEBAQUA
A4GNADCBiQKBgQDFxSTUwX5RD4AL2Ya5t5PAaNjcwPa3Km40uaPKSHlU8AMydxC1
wB4L0k3Ms9uh98R+kIJS+TxdfDaYxk/GdDYI1CMm4TM+BLHGAVA2DeNf2hBhBRKb
TAgxCxXwORJQSB/B+1r0/ZiQ2ig5Jzr8xGHz+tBsHYZ+t+RmjZPQFjnlewIDAQAB
MA0GCSqGSIb3DQEBBQUAA4GBABqVuloGWHReSGLY1yAs20uhJ3j/9SvtoueyFBag
z5jX4BNO/4yhpKEpCGmzYtjr7us3v/s0mKoIVvAgah778rCZW3kF1Y6xR6TYqZna
1ryKB50/MJg9PC4LNL+sAu+WSslOf6+6Ru5N3JjhIZST8edJsGDi6/5HTKoqyvkp
wOMn
-----END CERTIFICATE-----
subject=/CN=www.exceliance.fr
issuer=/CN=www.exceliance.fr
---
No client certificate CA names sent
---
SSL handshake has read 604 bytes and written 319 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1
Cipher : AES256-SHA
Session-ID: CF9B7BFF64DE0B332CE9A76896EC1C59C941340D6913612286113FA1F7E09E88
Session-ID-ctx:
Master-Key: C6893078E49626DAF329C61774BA5A35E0264818E0D76542F25BB958584B835154402E02F9B722DD94C56B14EBB14D46
Key-Arg : None
Start Time: 1346750742
Timeout : 300 (sec)
Verify return code: 18 (self signed certificate)
---
GET / HTTP/1.0
HTTP/1.1 200 OK
Date: Tue, 04 Sep 2012 09:26:44 GMT
Server: Apache/2.2.16 (Debian)
Last-Modified: Tue, 04 Sep 2012 09:10:01 GMT
ETag: "a35d1-e-4c8dc9f7d6c40"
Accept-Ranges: bytes
Content-Length: 14
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
Welcome page.
closed
Related articles
- Enhanced SSL load-balancing with Server Name Indication (SNI) TLS extension
- Scaling out SSL
- Benchmarking SSL performance
- Maintain affinity based on SSL session ID

Thanks for the how-to Baptiste!
Do you know how well this scales in terms of CPU utilization for SSL processing – can it take advantage of multiple cores?
Hi Kyle,
It scales quite well, as Willy explained on HAProxy Mailing list.
“4000 SSL connections per second and 300 Mbps is what we got out of a dual-core Atom D510 at 1.66 GHz, in SSLv3 running over 4 processes (hyperthreading was enabled) ”
HAProxy did a bit more that stud on the same platform, same benchmark.
cheers
Can you clarify the 4 process config a little bit? Is that just nbproc (http://code.google.com/p/haproxy-docs/wiki/ProcessManagement#nbproc_) ?
I guess this is how Willy ran his bench.
But bear in mind that multi-process in HAProxy has still a lot of limitations. They don’t apply on SSL, since SSL uses a cache in a shared mem (which is not the case for other stuff in HAProxy).
cheers
Pingback: Haproxy SSL support » Mind End | Mind End
First I’d like to say, AWESOME! Finally this is a great feature addition!
Secondly I would like to note I am looking on the haproxy website and this release is still not in the stable release state (http://haproxy.1wt.eu/git?p=haproxy.git;a=commit;h=ee2e3a4027e3a35c43790667a8d61865d93f7ec3). v1.5-development
FYI for people just copy and pasting the setup instructions
Nick, as indicated on the mailing list post, 1.5 is still in development and this is a preview of the next development release. Basically it’s a merge in the master tree of several months of hard work, that’s why it was posted. We’re trying to fix as many issues as we can before the -dev12 version so that users can safely try it without bothering with build issues for instance.
Baptiste, could you please update your link to point to 20120905, we fixed a number of build issues so it will save some unpleasant experience to new visitors.
@Kyle: yes that’s how we did it, 4 processes (nbproc 4) on the machine. There are indeed issues with health checks and stats with that number of processes, but it was just for experimentation. We want to work further to dedicate processes to SSL offloading, where this will not be much a problem. Also it’s quite possible to replace stunnel with an haproxy running with nbproc 2 for instance. You won’t get less stats nor health checks
If we find time, we’ll merge Emeric’s multi-node SSL synchronization code, which is awesome and allows many hosts to share the same SSL sessions. That way you can build farms out of multiple multi-core machines
In summary, scaling out SSL would be possible, have a look here for how to do it with stud: http://blog.exceliance.fr/2011/11/07/scaling-out-ssl/
Baptiste
Pingback: Enhanced SSL load-balancing with Server Name Indication (SNI) TLS extension | Exceliance – Aloha Load Balancer
Pingback: Scaling out SSL | Exceliance – Aloha Load Balancer
Pingback: Benchmarking SSL performance | Exceliance – Aloha Load Balancer
Pingback: Sysadmin Sunday 96 - Server Density Blog
Pingback: How to get SSL with HAProxy getting rid of stunnel, stud, nginx or pound | Exceliance – Aloha Load Balancer
Pingback: SSL Client certificate management at application level | Exceliance – Aloha Load Balancer
Pingback: » Load Balancing with HAProxy 1.4 thejimmahknows
Have a problem: My configuration is:
frontend ft_test
mode http
bind 0.0.0.0:443 ssl /etc/ssl/output.pem # basic conf require only 1 keyword
# other (self described) options are: [ciphers ] [nosslv3] [notlsv1]
default_backend bk_test
backend bk_test
mode http
server srv1 0.0.0.0:8888
when i use (haproxy -f /etc/haproxy/haproxy.cfg -c) or try restart haproxy? System give me error like this:
[ALERT] 332/074210 (31836) : parsing [/etc/haproxy/haproxy.cfg:42] : ‘bind’ only supports the ‘transparent’, ‘defer-accept’, ‘name’, ‘id’, ‘mss’ and ‘interface’ options.
[ALERT] 332/074210 (31836) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
[ALERT] 332/074210 (31836) : Fatal errors found in configuration.
Where my problem? I can’t find it
Hi,
You have not compiled HAProxy with SSL support: USE_OPENSSL=yes
cheers
Hi Baptiste,
I’ve tested in my project. Says the server is “http://192.168.0.1:80″ and the frontend is “https://192.168.0.2:8443″, when i connect it from chrome with url “https://192.168.0.2:8443/login.jsp”, it go well(successfully open the page of http://192.168.0.1:80/login.jsp). But then when the server try to redirect to the main page “http://192.168.0.1:80/main.jsp”, the frontend(my chrome) actually try to connect “http://192.168.0.2:8443/main.jsp”, of course it failed. How can i fix it?
Thx
Then I changed the url to https://192.168.0.2:8443/main.jsp(just add a letter s), it went well again. I know it was because my configuration, but i’m not sure what’s the correct configuration.
Hi Michael,
Today I wrote an article to answer you: http://blog.exceliance.fr/2013/02/26/ssl-offloading-impact-on-web-applications/
Enjoy!