HAProxy sits in front of everything else, so when it misbehaves, everything misbehaves. It is also one of the most capable pieces of software in a typical stack, and most setups use a fraction of it.
This series goes from a first TCP load balancer to an HAProxy that gets its certificates by itself, checks client certificates, filters attacks, finds its backends in Consul and changes configuration through an API. Each part is a standalone guide with configuration you can copy. Read in order, they build up one production setup.
What you’ll build #
- Load balancing at layer 4 and layer 7, with health checks and high availability.
- HTTPS that renews itself with Let’s Encrypt, and the tools to debug headers when an application behind HAProxy acts up.
- Security at the edge: mutual TLS for API clients, and a web application firewall with Coraza and the OWASP Core Rule Set.
- More than HTTP: highly available DNS over UDP and TCP.
- Dynamic infrastructure: backends discovered through Consul, configuration changed at runtime with the Data Plane API, and the whole install automated with Ansible.
- Observability with HAProxy’s built-in Prometheus exporter and Grafana.
How the series fits together #
- Foundations (parts 1–3). Install HAProxy and balance TCP traffic, add HTTPS with Let’s Encrypt (HTTP-01 and DNS-01), and learn to see which headers HAProxy passes on.
- Security (parts 4–5). Require client certificates with mTLS, then put Coraza-SPOA in front of your applications as a WAF.
- Beyond HTTP (part 6). Load balance DNS. It pairs well with the BIND DNS series.
- Dynamic configuration (parts 7–9). Generate backends from Consul with consul-template, change running configuration through the Data Plane API, then automate the HAProxy 3.1 and Data Plane API install with Ansible.
- Observability (part 10). Scrape HAProxy’s metrics and graph them.
Pick a path #
- Just need HTTPS in front of an app: parts 1, 2 and 3.
- Exposing APIs to partners or devices: parts 2, 4 and 5.
- Running HAProxy in a changing environment: parts 7, 8 and 9.
Before you start #
You need a Linux server with root access. The install steps cover RHEL as well as Debian and Ubuntu. Some features need a recent HAProxy; where that matters, the part says which version. Basic HTTP and TLS knowledge helps. The rest is explained along the way.