Search code examples
sslsubdomainreverse-proxyhaproxy

Reverse Proxing with HA Proxy


I'm trying to use HA Proxy as Reverse Proxy for LoadBalancing and Health-Check Purpose mainly.

Therefore, I have to address different domains with several subdomains and/or subpaths.

  1. https://sub1.example1.com
  2. https://subsub.sub1.example1.com
  3. https://sub2.example2.com
  4. https://example3.com/path1

Unfortunately, I'm not finding an opportunity to define a frontend for each Domain to bind the SSL-cert-file to. Additionally, I'm not pretty sure whether HAProxy provides something like ProxyPass to handle the "path"-Stuff.

Can somebody please give me an example how to solve this with HAProxy?

Thanks


Solution

  • You can have a single frontend that handles all of the subdomains and use ACL's to route to different backends. You define your certificates on the bind line and multiple can be specified. I'm not quite sure what you mean by the "ProxyPass to handle the "path"-Stuff" but if you provide more detail I can help. HAProxy is extremely flexible.

    provides something like ProxyPass to handle the "path"-Stuff.

    Example of how you might handle the multiple subdomains:

    defaults
        mode http
    
    frontend fe_main
        bind :80
        # define all certificates
        bind :443 ssl crt /etc/haproxy/ssl/sub1.example.com.pem crt /etc/haproxy/ssl/sub2.example.com.pem crt /etc/haproxy/ssl/example3.com.pem
    
        use_backend be_sub1 if { req.hdr(host) sub1.example.com }
        use_backend be_sub2 if { req.hdr(host) sub2.example.com }
        default_backend be_catchall
    
    backend be_sub1
        server app1 192.168.1.10:80 check
    
    backend be_sub2
        server app1 10.2.0.4:443 check ssl verify none
    
    backend be_catchall
        server catchall1 10.3.2.5:80 check