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

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)

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.