How to set up SSL passthrough with multiple domains with HAproxy?

Posted February 21, 2017 44.8k views

How does one set up HAproxy for multiple domains, to multiple backends while passing through SSL? I would also be open to an nginx solution

Example in diagram for a better explanation:

                              backend_domain_a            .->
             |            |
             +-> haproxy -+
             |            |   backend_domain_b'            '-> 789.789.789.789

Note Each backend server will be issueing their own certificate. Hence the need for SSL passthrough.

I have this configuration, but doesn’t work for multiple reasons (the key one being the missing port number):

frontend www
        bind *:80
        bind *:443
        option tcplog

        acl host_domain_a hdr(host) -i
        acl host_domain_b hdr(host) -i

        use_backend backend_domain_a if host_domain_a
        use_backend backend_domain_b if host_domain_b

backend backend_domain_a
        server web_a check

backend backend_domain_b
        server web_b 789.789.789.789 check

In others words, I want Haxproxy to not terminate the SSL.

I initially wanted to do this with Nginx but apparently it can’t act as a non-terminating point while reading the host details (though might be available in future versions with ssl preread)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

You need to use HAProxy as a Level 4 load balancer. This means explicitly setting “mode tcp” under frontend, backend a, and backend b. See the HAProxy section of this guide for details except note that you are forwarding to two domains, not one.

by Mitchell Anicas
A tutorial on how to use HAProxy as a Layer 4 Load Balancer for WordPress Application Servers. It assumes that your setup includes a WordPress application server that connects to a separate MySQL database server.