Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
haproxytechblog / blog20181127-01.cfg
Last active January 24, 2024 13:23
Bot Protection with HAProxy
backend per_ip_and_url_rates
stick-table type binary len 8 size 1m expire 24h store http_req_rate(24h)
backend per_ip_rates
stick-table type ip size 1m expire 24h store gpc0,gpc0_rate(30s)
@haproxytechblog
haproxytechblog / blog20181210-01.sh
Last active December 10, 2018 18:41
Building a Service Mesh with HAProxy and Consul
cd blog/building_service_mesh
docker-compose up -d consul-server
# Wait for consul-server to bootstrap itself
sleep 10
# Create ACL token that agents use to connect to consul-server
docker-compose exec consul-server curl --request PUT --header "X-Consul-Token: mastertoken" --data '{ "ID": "agenttoken", "Name": "Agent Token", "Type": "client", "Rules": "node \"\" { policy = \"write\" } service \"\" { policy = \"write\" }" }' http://localhost:8500/v1/acl/create
sleep 1
@haproxytechblog
haproxytechblog / blog20181219-01.cfg
Last active December 20, 2018 18:39
HAProxy 1.9 Has Landed
option http-use-htx
@haproxytechblog
haproxytechblog / blog20190115-01.cfg
Last active February 26, 2021 16:44
Using HAProxy as an API Gateway, Part 2 [Authentication]
Authorization: Bearer <token>
@haproxytechblog
haproxytechblog / blog20190116-01.cfg
Created January 16, 2019 18:40
HAProxy 1.9.2 Adds gRPC Support
frontend fe_mysite
bind :443 ssl crt /path/to/cert.pem alpn h2,http/1.1
default_backend be_servers
@haproxytechblog
haproxytechblog / blog20121029-01.cfg
Last active October 16, 2019 15:42
HAProxy Log Customization
defaults
log-format "<format-string>"
@haproxytechblog
haproxytechblog / blog20190207-01.sh
Last active August 9, 2023 22:05
Introduction to HAProxy Logging
sudo apt install -y rsyslog
@haproxytechblog
haproxytechblog / blog20190214
Created February 14, 2019 14:31
Power of Two Load Balancing
GET /MyTime/bob HTTP/1.1
Host: mytime.example.local
HTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.6.7
Date: Tue, 22 Jan 2019 16:38:11 GMT
<HTML><BODY>Hello Bob Smith, your IP address is 198.18.0.7 and your local time is 10:38.</BODY></HTML>
@haproxytechblog
haproxytechblog / blog20190228-01.cfg
Last active March 1, 2019 18:26
API Gateway Part 3
backend apiservers
balance roundrobin
server server1 192.168.50.3:80 check
@haproxytechblog
haproxytechblog / blog20190314-01.sh
Last active March 14, 2019 16:10
IP Masking in HAProxy
Feb 8 20:51:28 server1 haproxy[4718]: 192.168.50.5 [08/Feb/2019:20:51:28.816] website~ servers/server1 0/0/0/1/1 304 180 - - ---- 1/1/0/1/0 0/0 "GET / HTTP/1.1"