Skip to content

Instantly share code, notes, and snippets.

@vpnwall-services
Last active July 13, 2023 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpnwall-services/719a120d340410ec527e1ce3da16eab1 to your computer and use it in GitHub Desktop.
Save vpnwall-services/719a120d340410ec527e1ce3da16eab1 to your computer and use it in GitHub Desktop.
[HAPROXY 101] Haproxy 101 #haproxy #debian #101

HAPROXY 101

  • Stop sending requests to node to enable maintenance on it echo "set server backend_name/svc_name state drain" | socat stdio /var/run/haproxy/admin.sock

  • Start sending requests to node to disable maintenance on it echo "set server backend_name/svc_name state ready" | socat stdio /var/run/haproxy/admin.sock

  • Show statistics echo "show stat" | socat stdio /var/run/haproxy/admin.sock | cut -d "," -f 1-2,5-10,34-36 | column -s, -t

  • [TCP] Wildcard domain match based redirection

acl api_urls req.ssl_sni -m end .test.local
use_backend backend_api if api_urls
  • [TCP] IP address based redirection
acl acl_frontend_green src xxx.xxx.xxx.xxx/xx #blue_green_deployment
use_backend backend_green if acl_frontend_green
  • [HTTP] SSL Redirection
redirect scheme https code 301 if !{ ssl_fc }
  • [HTTP] Letsencrypt path based redirection
acl letsencrypt-acl path_beg /.well-known/acme-challenge/
use_backend letsencrypt_backend if letsencrypt-acl
  • [HTTP] Backend servers count based redirection
# frontend
acl backend_ko nbsrv(backend_prod) lt 1
use_backend backend_failed if backend_ko
default_backend backend_prod

# backend_failed
backend backend_failed
acl failed_path hdr_beg(host) -i sub.domain.local
http-request redirect code 307 location https://another.domain.local if !failed_path
http-request redirect code 307 location https://new.domain.local if failed_path

# backend_prod
backend backend_prod
fullconn 20000
balance roundrobin
cookie SERVERUSED insert indirect nocache
default-server check maxconn 500
mode http
log global
server server1 xxx.xxx.xxx.xxx:443 ssl check verify none cookie server1 check maxconn 20000 send-proxy 
server server2 xxx.xxx.xxx.xxx:443 ssl check verify none cookie server2 check maxconn 20000 send-proxy 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment