Skip to content

Instantly share code, notes, and snippets.

@dogukancagatay
Last active September 3, 2022 18:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dogukancagatay/2c483246bbe3897763d73c98dd878927 to your computer and use it in GitHub Desktop.
Save dogukancagatay/2c483246bbe3897763d73c98dd878927 to your computer and use it in GitHub Desktop.
Basic HAProxy Setup for Multiple Services with Docker
version: "3"
services:
haproxy:
image: haproxy:2.1-alpine
container_name: ingress-haproxy
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
ports:
- 8406:8404
- 80:80
- 443:443
- 5672:5672
- 15672:15672
- 6379:6379
restart: unless-stopped

Basic HAProxy Setup for Multiple Services with Docker

  • RabbitMQ
  • Redis
  • Web Server/Ingress
global
log 127.0.0.1 local1
maxconn 50000
defaults
log global
mode tcp
option tcplog
retries 3
option redispatch
option log-health-checks
timeout connect 3s
timeout client 6s
timeout server 6s
listen stats
bind *:8404
mode http
option http-use-htx
http-request use-service prometheus-exporter if { path /metrics }
stats enable
stats uri /stats
stats refresh 10s
listen lb-tcp-1
bind *:80
mode tcp
balance leastconn
option tcplog
option tcp-check
server srv-01 srv-01:80 check inter 5s
server srv-02 srv-02:80 check inter 5s
listen lb-tcp-2
bind *:443
mode tcp
balance leastconn
option tcplog
option tcp-check
server srv-01 srv-01:443 check inter 5s
server srv-02 srv-02:443 check inter 5s
listen rabbitmq
bind *:5672
mode tcp
balance leastconn
option tcplog
option tcp-check
option clitcpka
timeout client 3h
timeout server 3h
server srv-01 srv-01:5672 check inter 5s
server srv-02 srv-02:5672 check inter 5s
listen rabbitmq-http
bind *:15672
mode http
balance roundrobin
option httplog
option httpchk
server srv-01 srv-01:15672 check inter 5s
server srv-02 srv-02:15672 check inter 5s
listen keydb
bind *:6379 name redis
mode tcp
balance first
option tcplog
option tcp-check
#uncomment these lines if you have basic auth
#tcp-check send AUTH\ yourpassword\r\n
#tcp-check expect +OK
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:active-replica
tcp-check send QUIT\r\n
tcp-check expect string +OK
server srv-01 srv-01:6379 check inter 1s
server srv-02 srv-02:6379 check inter 1s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment