Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Created June 2, 2026 19:06
Show Gist options
  • Select an option

  • Save haproxytechblog/0848e74f9db1abe9a02c40bfdf8ee742 to your computer and use it in GitHub Desktop.

Select an option

Save haproxytechblog/0848e74f9db1abe9a02c40bfdf8ee742 to your computer and use it in GitHub Desktop.
Announcing HAProxy 3.4
global
stats socket /run/haproxy/admin.sock user haproxy group haproxy mode 660 level admin
defaults mydefaults
log global
mode http
option httplog
option dontlognull
timeout connect 10m
timeout client 10m
timeout server 10m
frontend mysite
bind :80
use_backend %[path,map_beg(virt@paths.map)]
default_backend webservers
backend webservers
server web1 127.0.0.1:8080
# Add a backend named 'test-backend'
echo "add backend test-backend from mydefaults mode http" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# 'New backend registered.'
# Add a server to the backend
echo "add server test-backend/server1 127.0.0.1:3000 check" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# 'New server registered.'
# Enable the server
echo "enable server test-backend/server1" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# Enable health checks
echo "enable health test-backend/server1" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# Publish the backend
echo "publish backend test-backend" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# 'Backend published.'
# Add an entry to the map file
echo "add map virt@paths.map /test test-backend" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# Show map displays entry_cnt
echo "show map" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# id (file) description
5 (virt@paths.map) pattern loaded from file 'virt@paths.map' used by map at file '/etc/haproxy/hapee-lb.cfg' line 45. curr_ver=0 next_ver=0 entry_cnt=1
# Place the server into maintenance mode
echo "set server test-backend/server1 state maint" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# Wait for the server to be removable
# then remove the server
echo "wait 2s srv-removable test-backend/server1; del server test-backend/server1" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# 'Server deleted.'
# Unpublish the backend
echo "unpublish backend test-backend" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# 'Backend unpublished.'
# Wait for the backend to be removable
# then delete the backend
echo "wait 2s be-removable test-backend; del backend test-backend" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# 'Backend deleted.'
# Delete the map file entry
echo "del map virt@paths.map /test" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# Show map displays entry_cnt
echo "show map" | sudo socat stdio unix-connect:/run/haproxy/admin.sock
# id (file) description
5 (virt@paths.map) pattern loaded from file 'virt@paths.map' used by map at file '/etc/haproxy/hapee-lb.cfg' line 45. curr_ver=0 next_ver=0 entry_cnt=0
frontend mysite
bind :80
use_backend webservers
# Enable QMux in the backend
backend webservers
server myserver 127.0.0.1:443 ssl verify none alpn h3,h2
# Enable QMux in the frontend
frontend qmux-fe
bind :443 ssl crt /etc/haproxy/ssl.pem alpn h3,h2
http-request return status 200 content-type text/plain string "Hello, qmux!"
backend web_servers
filter comp-res
compression algo gzip
compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json
log-profile syslog
log-tag "haproxy"
on close format "$HAPROXY_HTTP_LOG_FMT"
on http-req format "%[var(req.log_message)]"
frontend mysite
bind :80
acl is_evil_client req.hdr(user-agent) -m sub evil
http-request set-var(req.log_message) str("Blocking evil client") if is_evil_client
http-request do-log profile syslog
http-request deny if is_evil_client
global
cpu-policy performance threads-per-core 1
cpu-affinity per-core
global
cpu-affinity per-ccx
max-threads-per-group 4
healthcheck mycheck
type httpchk
http-check connect alpn h2
http-check send meth HEAD uri /health ver HTTP/2 hdr Host www.example.com
backend webservers
server web1 10.0.0.1:80 check healthcheck mycheck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment