Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
haproxytechblog / blog20201222-01.cfg
Last active July 23, 2021 12:21
Circuit Breaking in HAProxy
backend serviceA
default-server maxconn 30 check observe layer7 error-limit 50 on-error mark-down inter 1s rise 30 slowstart 20s
server s1 192.168.0.10:80
server s2 192.168.0.11:80
@haproxytechblog
haproxytechblog / blog20201221-01.cfg
Created December 21, 2020 14:53
Route SSH Connections with HAProxy
frontend fe_ssh
bind *:2222 ssl crt /etc/haproxy/certs/ssl.pem
mode tcp
log-format "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq dst:%[var(sess.dst)] "
tcp-request content set-var(sess.dst) ssl_fc_sni
use_backend %[ssl_fc_sni]
@haproxytechblog
haproxytechblog / blog20201208-01.cfg
Created December 8, 2020 16:57
HTTP Keep-Alive, Pipelining, Multiplexing and Connection Pooling
backend servers
# connections will be marked as private and can't be shared between users
server srv1 10.0.0.1:443 check ssl sni hdr(Host)
# not marked private, is reusable
server srv2 10.0.0.2:443 check ssl sni str(my.domain.com)
@haproxytechblog
haproxytechblog / blog20201116-01.cfg
Last active November 16, 2020 18:09
HAProxy Log Sampling
global
log 127.0.0.1:514 sample 1:10 local0 info
@haproxytechblog
haproxytechblog / blog20201110-01.cfg
Created November 10, 2020 14:45
Layer 4 and Layer 7 Proxy Mode
defaults
# mode is inherited by sections that follow
mode tcp
frontend db
# receives traffic from clients
bind :3306
default_backend databases
backend databases
@haproxytechblog
haproxytechblog / blog20201105-01.cfg
Last active November 5, 2020 17:56
Announcing HAProxy 2.3
log-forward syslog-lb
bind :::7514 # Listen on TCP IPv4/IPv6
dgram-bind :::7514 # Listen on UDP IPv4/IPv6
# load balance messages on 4 udp syslog servers
log 10.1.0.2:10001 format rfc5424 sample 1:4 local0 info
log 10.1.0.3:10002 format rfc5424 sample 2:4 local0 info
log 10.1.0.4:10003 format rfc5424 sample 3:4 local0 info
log 10.1.0.5:10004 format rfc5424 sample 4:4 local0 info
@haproxytechblog
haproxytechblog / blog20201021-01.cfg
Created October 21, 2020 13:38
Accelerate Your APIs by Using the HAProxy Cache
global
# global settings
defaults
# default settings
cache mycache
total-max-size 4095 # MB
max-object-size 10000 # bytes
max-age 30 # seconds
@haproxytechblog
haproxytechblog / blog20201019-01.cfg
Created October 19, 2020 16:58
HAProxy and HTTP Strict Transport Security (HSTS)
frontend www.mywebsite.com
bind :80
bind :443 ssl crt /etc/ssl/certs/mywebsite.com.pem
http-request redirect scheme https code 301 unless { ssl_fc }
default_backend servers
@haproxytechblog
haproxytechblog / blog20200925-01.html
Last active April 3, 2023 14:13
Serve Dynamic Custom Error Pages with HAProxy
HTTP/1.1 404 Not Found
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>404 Not Found</title>
@haproxytechblog
haproxytechblog / blog20200921-01.conf
Created September 21, 2020 14:18
CVE-2020-15598: HAProxy Enterprise Unaffected Due to ModSecurity Hardening Measures!
SecRule ARGS "@rx \d" "id:1000,phase:2,deny,capture,log,msg:'Numeric payload'"