Search code examples
nginxhaproxy

HAproxy port 80 and 443 to backend:80 and backend:443


How can I improve on the following config, to get haproxy to listen on port 80 and 443 and pass requests to backend:80 or backend:443 depending.

Is there a better way to do this?

frontend http
    bind    35.154.100.100:80
    default_backend http_nginx_pool

frontend https
    bind    35.154.100.100:443
    default_backend https_nginx_pool

backend http_nginx_pool
    mode tcp
    server nginx2 10.233.32.143:80 check

backend https_nginx_pool
    mode tcp
    server nginx2 10.233.32.143:443 check

Solution

  • Tested this on HAProxy 1.5 worked fine

    frontend http-https-in
    bind    35.154.100.100:80
    bind    35.154.100.100:443
    
    use_backend http_nginx_pool    if !{ ssl_fc }
    use_backend https_nginx_pool   if { ssl_fc }
    
    backend http_nginx_pool
        mode http
        server nginx2 10.233.32.143:80 check
    
    backend https_nginx_pool
        mode http
        server nginx2 10.233.32.143:443 check