Claude-skill-registry haproxy
HAProxy load balancer configuration and management. Set up TCP/HTTP load balancing, SSL termination, health checks, ACLs, and high availability. Use when working with HAProxy, load balancing, reverse proxy, TCP proxying, or high-traffic applications.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/haproxy-housegarofalo-claude-code-base" ~/.claude/skills/majiayu000-claude-skill-registry-haproxy && rm -rf "$T"
manifest:
skills/data/haproxy-housegarofalo-claude-code-base/SKILL.mdsource content
HAProxy Load Balancer Skill
Configure and manage HAProxy for high-performance load balancing, SSL termination, and reverse proxying.
Triggers
Use this skill when you see:
- haproxy, ha proxy, load balancer
- tcp proxy, http proxy, reverse proxy
- ssl termination, health check
- backend server, frontend, acl
Instructions
Basic Configuration Structure
# /etc/haproxy/haproxy.cfg global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin stats timeout 30s user haproxy group haproxy daemon maxconn 4096 defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 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
HTTP Load Balancing
frontend http_front bind *:80 default_backend http_back option forwardfor backend http_back balance roundrobin option httpchk GET /health http-check expect status 200 server web1 192.168.1.10:8080 check server web2 192.168.1.11:8080 check server web3 192.168.1.12:8080 check backup
HTTPS with SSL Termination
frontend https_front bind *:443 ssl crt /etc/haproxy/certs/combined.pem bind *:80 redirect scheme https code 301 if !{ ssl_fc } default_backend https_back # HSTS header http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains" backend https_back balance leastconn option httpchk GET /health server web1 192.168.1.10:8080 check server web2 192.168.1.11:8080 check
TCP Load Balancing
frontend tcp_front bind *:3306 mode tcp default_backend mysql_back backend mysql_back mode tcp balance roundrobin option mysql-check user haproxy server db1 192.168.1.20:3306 check server db2 192.168.1.21:3306 check backup
ACL-Based Routing
frontend http_front bind *:80 # Define ACLs acl is_api path_beg /api acl is_static path_beg /static acl is_admin path_beg /admin acl host_app hdr(host) -i app.example.com acl host_api hdr(host) -i api.example.com # Route based on ACLs use_backend api_back if is_api use_backend api_back if host_api use_backend static_back if is_static use_backend admin_back if is_admin default_backend app_back backend api_back balance roundrobin server api1 192.168.1.30:8080 check server api2 192.168.1.31:8080 check backend static_back balance roundrobin server static1 192.168.1.40:80 check backend admin_back balance roundrobin server admin1 192.168.1.50:8080 check backend app_back balance roundrobin server app1 192.168.1.10:8080 check server app2 192.168.1.11:8080 check
Health Checks
backend http_back # HTTP health check option httpchk GET /health HTTP/1.1\r\nHost:\ localhost http-check expect status 200 # Advanced health check http-check send meth GET uri /health ver HTTP/1.1 hdr Host localhost http-check expect status 200 server web1 192.168.1.10:8080 check inter 3000 fall 3 rise 2 server web2 192.168.1.11:8080 check inter 3000 fall 3 rise 2 backend tcp_back mode tcp option tcp-check tcp-check connect tcp-check send PING\r\n tcp-check expect string +PONG server redis1 192.168.1.60:6379 check
Rate Limiting
frontend http_front bind *:80 # Define rate limit table stick-table type ip size 100k expire 30s store http_req_rate(10s) # Track requests per IP http-request track-sc0 src # Deny if rate exceeds 100 requests per 10 seconds http-request deny deny_status 429 if { sc_http_req_rate(0) gt 100 } default_backend http_back
Session Persistence (Sticky Sessions)
backend app_back balance roundrobin cookie SERVERID insert indirect nocache server web1 192.168.1.10:8080 check cookie web1 server web2 192.168.1.11:8080 check cookie web2
Stats Dashboard
listen stats bind *:8404 stats enable stats uri /stats stats refresh 10s stats auth admin:password stats admin if LOCALHOST
Logging Configuration
global log 127.0.0.1:514 local0 info log 127.0.0.1:514 local1 notice defaults log global option httplog option dontlognull # Custom log format log-format "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
Docker Compose Example
version: '3.8' services: haproxy: image: haproxy:2.8 ports: - "80:80" - "443:443" - "8404:8404" volumes: - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro - ./certs:/etc/haproxy/certs:ro restart: unless-stopped networks: - app-network web1: image: nginx:alpine networks: - app-network web2: image: nginx:alpine networks: - app-network networks: app-network: driver: bridge
Common Commands
# Check configuration haproxy -c -f /etc/haproxy/haproxy.cfg # Reload configuration (graceful) sudo systemctl reload haproxy # View stats via socket echo "show stat" | sudo socat stdio /run/haproxy/admin.sock # Disable server echo "disable server http_back/web1" | sudo socat stdio /run/haproxy/admin.sock # Enable server echo "enable server http_back/web1" | sudo socat stdio /run/haproxy/admin.sock # View server status echo "show servers state" | sudo socat stdio /run/haproxy/admin.sock
Best Practices
- Health Checks: Always configure health checks for backends
- Timeouts: Set appropriate timeouts for your application
- SSL: Use strong ciphers and enable HSTS
- Logging: Enable detailed logging for troubleshooting
- Stats: Enable stats page for monitoring (protect with auth)
- Backup Servers: Configure backup servers for failover
Common Workflows
Set Up Load Balancer
- Install HAProxy:
apt install haproxy - Configure frontend and backend
- Set up health checks
- Test configuration:
haproxy -c -f /etc/haproxy/haproxy.cfg - Start service:
systemctl start haproxy - Monitor via stats page
Add SSL Termination
- Obtain SSL certificate
- Combine cert and key:
cat cert.pem key.pem > combined.pem - Configure HTTPS frontend with SSL binding
- Add HTTP to HTTPS redirect
- Reload configuration