# HAProxy configuration showing redirecting to different backends
global
    log 192.168.50.2:514 local0
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    ssl-default-bind-ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
    ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

defaults
    log global
    option httplog
    timeout connect 5s
    timeout client  1m
    timeout server  1m

frontend mywebsite
    bind :80
    balance roundrobin
    mode http
    acl apipath path_beg /api/
    acl apihost req.hdr(Host) -i -m dom api.mywebsite.com
    redirect prefix http://api.mywebsite.com if apipath
    use_backend apiservers if apihost
    default_backend webservers

backend webservers
    option httpchk HEAD /health
    server web1 192.168.0.3:80 check maxconn 20
    server web2 192.168.0.4:80 check maxconn 20

backend apiservers
    option httpchk HEAD /health
    server api1 192.168.0.10:80 check maxconn 20
    server api2 192.168.0.11:80 check maxconn 20