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

February 21, 2017 198 views
Nginx Ubuntu Debian

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:

domain-a.com-.            .->
             |            |
             +-> haproxy -+
             |            |   backend_domain_b
domain-b.com-'            '-> 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 domain-a.com
        acl host_domain_b hdr(host) -i domain-b.com

        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)

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.
Have another answer? Share your knowledge.