High Availability Proxy (HAProxy)
Introduction
HAProxy is used as a load balancer and reverse proxy in front of the Helmut4 servers. In this setup, HAProxy provides a single entry point for users and services, handles HTTPS traffic, forwards requests to the available Helmut4 backend servers, and performs health checks to make sure traffic is only routed to reachable systems.
This guide describes how HAProxy can be added to an existing Docker Swarm environment and used together with Helmut4. The setup also uses Keepalived to provide a virtual IP address, which allows clients to connect to a stable address even if the active Docker manager node changes.
Portainer Stack Example
HAProxy Configuration Example
Certificate File: PEM
For HTTPS, HAProxy requires a certificate file that contains both the public certificate and the matching private key.
In this setup, only the following certificate file is needed:
The .pem file is used directly by HAProxy for SSL/TLS termination. It must contain both the certificate and the private key in the same file.
HAProxy references this file in the bind statement:
In the Docker Compose file, the PEM file is mounted into the HAProxy container as a Docker config:
The file mounted at /etc/ssl/certs/server.pem is the certificate file HAProxy uses for HTTPS connections.
A valid PEM file should contain the certificate and private key blocks, for example:
or:
How the Setup Works
Keepalived provides the virtual IP address:
Clients connect to this virtual IP address instead of connecting directly to a specific Helmut4 server.
HAProxy listens on ports 80 and 443:
HTTP traffic on port 80 is automatically redirected to HTTPS:
HAProxy then forwards the request to one of the configured Helmut4 backend servers:
Helmut4 - Exposed Taefik Ports
It is necessary to change the exposed ports of the Helmut4 Traefik container to different values, because HAProxy itself uses ports 80 and 443.
This change is only required if HAProxy is running on the same host as Helmut4.
A step-by-step guide for changing the ports can be found here: Change HTTP/HTTPS Ports
The backend servers are checked using the Helmut4 version endpoint:
Only servers that return the expected response are considered healthy and receive traffic.
Session Stickiness
The configuration uses source-IP-based stickiness:
This means that requests from the same client IP are routed to the same backend server for 30 minutes. This can be useful when backend-side session behavior or temporary state should stay on the same Helmut4 server during a user session.
HAProxy Statistics Page
The configuration also enables the HAProxy statistics interface on port 8083:
This page can be used to monitor backend server status, active connections, health checks, and traffic distribution.
For production environments, the username and password should be changed and access to the statistics page should be restricted.
Last updated