Files
gh-jeremylongshore-claude-c…/skills/load-balancer-configurator/assets/haproxy_template.conf
2025-11-30 08:19:50 +08:00

93 lines
3.0 KiB
Plaintext

# HAProxy Configuration File
# This template is designed for production environments.
# Adjust the values below to match your specific needs.
#
# For detailed documentation, refer to: http://www.haproxy.org/download/1.8/doc/configuration.txt
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
# Default SSL material locations
ssl-default-bind-ciphers ECDH+AESGCM:!DH
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
timeout http-request 10s
timeout http-keep-alive 15s
retries 3
option redispatch
option http-server-close
# Frontend: Incoming HTTP/HTTPS traffic
frontend http_frontend
bind *:80
mode http
# Add your ACLs and rules here for HTTP traffic
# Example:
# acl is_api path_beg /api
# use_backend api_backend if is_api
default_backend app_backend
frontend https_frontend
bind *:443 ssl crt /etc/haproxy/ssl/yourdomain.pem
mode http
# Add your ACLs and rules here for HTTPS traffic
# Example:
# acl is_api path_beg /api
# use_backend api_backend if is_api
http-request add-header X-Forwarded-Proto https
default_backend app_backend
# Backend: Application Servers
backend app_backend
balance roundrobin # Load balancing algorithm: roundrobin, leastconn, etc.
# Configure health checks
option httpchk GET /healthcheck # Replace with your application's health check endpoint
http-check expect status 200
# Add your application servers here
# Example:
server app1 <SERVER_IP_ADDRESS_1>:8080 check # Replace with your server IP and port
server app2 <SERVER_IP_ADDRESS_2>:8080 check # Replace with your server IP and port
server app3 <SERVER_IP_ADDRESS_3>:8080 check # Replace with your server IP and port
# Backend: API Servers (Example, if you have a separate API)
backend api_backend
balance leastconn
# Configure health checks
option httpchk GET /api/health # Replace with your API's health check endpoint
http-check expect status 200
# Add your API servers here
# Example:
server api1 <API_SERVER_IP_ADDRESS_1>:8081 check # Replace with your server IP and port
server api2 <API_SERVER_IP_ADDRESS_2>:8081 check # Replace with your server IP and port
# Statistics Page
listen stats
bind *:8080
mode http
stats enable
stats uri /haproxy_stats
stats realm Haproxy\ Statistics
stats auth <USERNAME>:<PASSWORD> # Replace with a strong username and password
stats admin if TRUE #Enable admin interface
# TCP Mode Backend (Example - for non-HTTP traffic)
# backend tcp_backend
# mode tcp
# balance roundrobin
# server tcp_server1 <TCP_SERVER_IP_ADDRESS_1>:3306 check
# server tcp_server2 <TCP_SERVER_IP_ADDRESS_2>:3306 check