Description
HAProxy (High Availability Proxy) est un load balancer TCP/HTTP ultra-performant utilisé en production par des milliers d'entreprises. Caractéristiques :
- ✅ Performance : peut gérer des centaines de milliers de connexions simultanées
- ✅ Load balancing : round-robin, least-conn, IP-hash, weighted, etc.
- ✅ Health checks : détection des backends down
- ✅ SSL/TLS termination avec SNI
- ✅ Sticky sessions (affinité de session)
- ✅ Rate limiting
- ✅ Logging détaillé
- ✅ Stats page (dashboard web)
- ✅ HA : active-passive, active-active
Public cible : production critique, gros volumes, entreprises.
Inconvénient : configuration verbeuse (fichier de config de plusieurs centaines de lignes possibles). Pas de GUI native.
Installation
Option 1 : Docker Compose
# docker-compose.yml
version: '3.8'
services:
haproxy:
image: haproxy:3.0
container_name: haproxy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "8404:8404" # Stats page
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
Option 2 : Fichier de configuration
# haproxy.cfg
global
maxconn 50000
log /dev/log local0
log /dev/log local1 notice
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
# Stats dashboard
frontend stats
bind *:8404
stats enable
stats uri /stats
stats refresh 10s
# Frontend HTTP (redirige vers HTTPS)
frontend http-in
bind *:80
redirect scheme https code 301
# Frontend HTTPS
frontend https-in
bind *:443 ssl crt /etc/ssl/certs/example.com.pem
default_backend app_servers
# Backend
backend app_servers
balance roundrobin
option httpchk GET /health
server app1 10.0.0.10:8080 check
server app2 10.0.0.11:8080 check
server app3 10.0.0.12:8080 check
Configuration
- Écrire le fichier de config (
haproxy.cfg) - Lancer le conteneur avec le volume
- Accéder aux stats :
http://IP:8404/stats - Reload :
docker exec haproxy haproxy -c -f /usr/local/etc/haproxy.cfgpour valider la config, puiskill -HUP 1pour reload
Alternatives
Open Source
- [[app-traefik]] — Plus simple, cloud-native
- [[app-caddy]] — Plus simple, HTTPS auto
- Nginx (standalone, pas NPM) — Très versatile
- Envoy (utilisé par Istio)
Comparaison HAProxy vs Traefik
| Critère | HAProxy | Traefik |
|---|---|---|
| Performance brute | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| Load balancing | ✅ Avancé | ✅ Basique |
| Auto-discovery | ❌ | ✅ |
| Config | Fichier statique | Dynamique |
| GUI | Stats only | Dashboard |
| SSL/TLS | ✅ | ✅ |
| Cible | Production critique | Cloud-native stacks |
Verdict : HAProxy pour les environnements exigeants (millions de connexions). Traefik pour la simplicité au quotidien.
Propriétaires (ce que HAProxy remplace)
- F5 BIG-IP (50k$+)
- Citrix ADC (NetScaler)
- AWS ALB (en partie)
- Cloudflare Load Balancing
Sécurité
- SSL/TLS moderne (TLS 1.3, SNI)
- Rate limiting par IP
- Connection limits
- ACLs puissantes
- Header rewriting
Ressources
- Documentation officielle
- Configuration reference
- HAProxy Enterprise (version commerciale)
