Files
mtusi2026lab3/infra/haproxy/haproxy.cfg
T

48 lines
1.3 KiB
INI

# Single public entry point in front of the API replicas.
# Backends are discovered through Docker DNS (service name `api`) and receive traffic only while /health/ready is 200.
global
log stdout format raw local0 info
defaults
mode http
log global
option httplog
option dontlognull
option forwardfor
timeout connect 1s
timeout client 30s
timeout server 10s
timeout http-request 10s
timeout http-keep-alive 5s
# Retried only when the connection to a replica fails, i.e. before the request was sent:
# a POST that reached a replica is never repeated by the balancer.
retries 2
option redispatch 1
resolvers docker
nameserver dns 127.0.0.11:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold valid 2s
hold other 2s
hold refused 2s
hold nx 2s
hold timeout 2s
hold obsolete 2s
accepted_payload_size 8192
frontend http
bind :8080
default_backend api
backend api
balance roundrobin
option httpchk GET /health/ready
http-check expect status 200
# A replica leaves rotation after 2 failed checks 1 s apart and returns after 2 successful ones.
default-server check inter 1s fall 2 rise 2 resolvers docker init-addr none
# Up to 4 replicas; slots without a resolved address stay in maintenance.
server-template api 4 api:8080