LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

haproxy

high-performance TCP/HTTP load balancer and proxy

TLDR

Start HAProxy
$ haproxy -f [/etc/haproxy/haproxy.cfg]
copy
Check configuration
$ haproxy -c -f [/etc/haproxy/haproxy.cfg]
copy
Reload configuration (soft-stop the old process once the new one is ready)
$ haproxy -f [config.cfg] -sf $(pidof haproxy)
copy
Start in daemon mode
$ haproxy -D -f [config.cfg]
copy
Start in master-worker mode (systemd-friendly, used by the official unit file)
$ haproxy -Ws -f [/etc/haproxy/haproxy.cfg] -p [/run/haproxy.pid]
copy
Show version
$ haproxy -v
copy

SYNOPSIS

haproxy [options] -f config

DESCRIPTION

HAProxy (High Availability Proxy) is a high-performance TCP/HTTP load balancer and reverse proxy that distributes incoming traffic across pools of backend servers. Its configuration is organized around frontends (which accept client connections on bound addresses and ports) and backends (which define the set of servers that handle requests, along with the balancing algorithm -- round-robin, least-connections, source-hash, and others). Active health checks continuously probe backend servers and automatically remove unhealthy nodes from rotation.Beyond basic load balancing, HAProxy provides SSL/TLS termination, HTTP header manipulation, content-based routing via ACLs, connection rate limiting, stick tables for session persistence, and a real-time statistics dashboard. It operates on an event-driven, multi-threaded worker model that can handle hundreds of thousands of concurrent connections with low latency and minimal resource consumption, making it a standard choice for high-traffic production environments.Modern deployments typically run it in master-worker mode (-W/-Ws), where a master process supervises one or more worker processes and can reload the configuration or reload binaries without dropping established connections.

PARAMETERS

-f file

Configuration file.
-c
Check configuration and exit.
-D
Daemon mode.
-sf pids
Soft-stop old processes.
-st pids
Hard-stop old processes.
-p pidfile
PID file path.
-n maxconn
Maximum connections.
-N maxconn
Default per-proxy maxconn.
-d
Debug mode; disables daemon mode and stays in the foreground.
-V
Verbose mode (cancels -q).
-q
Quiet mode; suppresses informational messages.
-v
Display version and build date.
-W
Master-worker mode: a master process supervises worker process(es) and reloads configuration without dropping connections.
-Ws
Master-worker mode with systemd `sd_notify` support; used by the official systemd unit.
-x socket
Retrieve listening sockets from an old process (used internally for seamless reloads).
-C dir
Change to this directory before loading configuration files.

CONFIG EXAMPLE

$ frontend http_front
    bind *:80
    default_backend http_back

backend http_back
    balance roundrobin
    server web1 192.168.1.1:80 check
    server web2 192.168.1.2:80 check
copy

INSTALL

sudo apt install haproxy
copy
sudo dnf install haproxy
copy
sudo pacman -S haproxy
copy
sudo apk add haproxy
copy
sudo zypper install haproxy
copy
brew install haproxy
copy
nix profile install nixpkgs#haproxy
copy

CAVEATS

Configuration changes require reload. Complex ACLs need careful testing. Statistics require separate configuration. SSL setup needs certificate management.

HISTORY

HAProxy was created by Willy Tarreau in 2000 and has become one of the most widely deployed load balancers. It powers high-traffic sites including GitHub, Reddit, and Stack Overflow.

SEE ALSO

nginx(1), envoy(1), traefik(1)

RESOURCES

Copied to clipboard
Kai