# HAProxy configuration showing choosing a different backend for static files
global
    maxconn 50000
    log /dev/log local0
    log /dev/log local1 notice
    user haproxy
    group haproxy
    stats socket /run/haproxy/admin.sock user haproxy group haproxy mode 660 level admin
    nbproc 1
    nbthread 4
    cpu-map auto:1/1-4 0-3
    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
    timeout connect 5s
    timeout client  5s
    timeout server  5s
    log global
    mode http
    option httplog
    option dontlognull
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

frontend public
    bind 10.0.0.3:80
    bind 10.0.0.3:443 ssl crt /etc/ssl/certs/mysite.pem
    redirect scheme https if !{ ssl_fc }
    acl static_files path_end .gif .png .jpg .css .js .svg .ttf .woff .woff2
    use_backend nginx if static_files
    default_backend nodejs

backend nodejs
    balance roundrobin
    cookie PHPSESSID prefix nocache
    option httpchk HEAD /
    default-server check maxconn 20
    server server1 10.0.1.3:80 cookie server1
    server server2 10.0.1.4:80 cookie server2 

backend nginx
    balance roundrobin
    option httpchk HEAD /
    server server1 10.0.1.5:80 check
    server server2 10.0.1.6:80 check

listen admin
  bind 0.0.0.0:8404
  stats enable
  stats uri /monitor
  stats refresh 5
