Process Control
haproxy -c -f <file>
Validate config and exit
haproxy -f <file>
Start with a config file
haproxy -f <dir>
Load all .cfg files in a directory
haproxy -D -f <file>
Fork into the background
haproxy -W -f <file>
Master-worker mode
haproxy -db -f <file>
Foreground, no master-worker
haproxy -d -f <file>
Debug mode, show events
haproxy -p <pidfile> -f <file>
Write PIDs to a file
haproxy -sf <pid>
Reload; old process stops gracefully
haproxy -st <pid>
Reload; old process killed at once
haproxy -v
Print version and build date
haproxy -vv
Build options and libraries
haproxy -S <bind> -W -f <file>
Open a master CLI socket
kill -USR2 <master-pid>
Reload in master-worker mode
kill -USR1 <pid>
Graceful stop
kill -TERM <pid>
Hard stop
haproxy -C <dir> -f <file>
Change directory first
Runtime API
stats socket /run/haproxy.sock mode 600 level admin
Enable the socket (global section)
echo "<command>" | socat /run/haproxy.sock
stdio
Run one command via socat
echo "show info;show stat" | socat
/run/haproxy.sock stdio
Several commands, semicolon-separated
socat /run/haproxy.sock readline
Interactive session
prompt
Toggle interactive mode
help
List the available commands
show info
Version, uptime, load, limits
show stat
CSV stats for all proxies
show stat typed
Typed output format
show stat json
Stats as JSON
show servers state <backend>
Server states and weights
show servers conn <backend>
Current and idle connections
show backend
List backends
show sess
List active streams
show errors
Last request/response errors
show pools
Memory pool usage
show activity
Internal event counters
show resolvers [<id>]
DNS resolver stats
set severity-output number
Add severity prefix to output
Servers and Limits
disable server <be>/<srv>
Put server in maintenance
enable server <be>/<srv>
Bring server back
set server <be>/<srv> state drain
Stop new sessions, keep persisted
set server <be>/<srv> state ready
Normal mode
set server <be>/<srv> state maint
Same as disable server
set server <be>/<srv> weight <n>[%]
Change load share
get weight <be>/<srv>
Show current and initial weight
set server <be>/<srv> addr <ip> [port
<p>]
Change server address
set server <be>/<srv> health
<up|stopping|down>
Force health state
set server <be>/<srv> agent
<up|down>
Force agent state
shutdown sessions server <be>/<srv>
Kill all streams to a server
set maxconn global <n>
Change global maxconn
set maxconn frontend <fe> <n>
Change frontend maxconn
set maxconn server <be>/<srv> <n>
Change server maxconn
set rate-limit connections global <n>
Change connection rate limit
Config Basics
global
Process-wide settings section
defaults
Shared mode and timeouts
frontend <name>
Where clients connect
backend <name>
Pool of servers
listen <name>
Frontend and backend in one
bind :<port>
Accept connections on a port
mode http
Layer 7 proxying
mode tcp
Layer 4 proxying
server <name> <ip>:<port> check
Add a checked server
balance roundrobin
Rotate across servers
balance leastconn
Fewest connections wins
balance source
Pin clients by source IP
default_backend <name>
Fallback backend
use_backend <name> if <acl>
Route by condition
acl <name> <criterion> <value>
Define a named condition
http-request deny if <acl>
Reject matching requests
http-request redirect scheme https unless { ssl_fc }
Force HTTPS
http-request set-header <name> <value>
Set a request header
option forwardfor
Add X-Forwarded-For
option httpchk
HTTP health checks
http-check send meth GET uri <path>
Choose the check request
timeout client|server|connect <t>
Set timeouts
maxconn <n>
Connection limit
stats uri <path>
Serve the stats page
stats auth <user>:<pass>
Protect the stats page
option httplog
Detailed HTTP logs