Search code examples
linuxhaproxy

HAPROXY how to sne drequest from port 80 to backend 80 nad port 443 to backned 443, all request layer 7


How can I set up haproxy to send layer 7 requests (by domain name) to the right backedn (port 80 and 443)

Here is the an example from my test haproxy config file:

frontend example.com
        bind            :80,:443
        acl             ACL_example.com hdr(host) -i example.com www.example.com
        use_backend             example_80 if ACL_example.com
        use_backend             example_443 if { dst_port 443 }

backend example_80
        balance         roundrobin
        server          001xx000x017        10.1.0.17:80        check
    
backend example_443
        balance         roundrobin
        server          001xx000x017        10.1.0.17:443       check

In advance, many thanks for the help.


Solution

  • I figured it out, this is the layout of the actual config file for haproxy that works now:

    frontend http_80
       42     bind      :80
       41     # example.com
       40     acl       ACL_example_com hdr(host) -i example.com www.example.com
       39
       38     # sc.example.com
       37     acl       ACL_sc_example_com hdr(host) -i sc.example.com www.sc.example.com
       36
       35     # 001x.example.com
       34     acl       ACL_001x_example_com hdr(host) -i 001x.example.com www.001x.example.com
       33
       32     # example.com
       31     acl       ACL_example_com hdr(host) -i example.com www.example.com
       30
       29     # 001x01dns.example.com
       28     acl       ACL_001x01dns_example_com hdr(host) -i 001x01dns.example.com www.001x01dns.example.com
       27
       26     # example.tech
       25     acl       ACL_example_tech hdr(host) -i example.tech www.example.tech
       24
       23
       22     use_backend   example_80 if ACL_example_com
       21     use_backend   sc_example_80 if ACL_sc_example_com
    ETC...
    

    same logic is for port 443. Works perfect now :)