Versões avaliadas:
Debian 13(Trixie) + HAProxy 3.0.11
Debian 9.3(Stretch) + HAProxy 1.7
Debian 8.5(Jessie) + HAProxy 1.6
Baixar a versão atual do HAProxy
# apt-get update
# apt-get install haproxy hatop <- haproxyctl removido do trixie
Verificando a versão instalada:
# haproxy -v
HAProxy version 3.0.11-1+deb13u2 2026/02/11 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2029.
Known bugs: http://www.haproxy.org/bugs/bugs-3.0.11.html
Running on: Linux 6.17.13-2-pve #1 SMP PREEMPT_DYNAMIC PMX 6.17.13-2 (2026-03-13T08:06Z) x86_64
A configuração do arquivo hosts é para configurar o parâmetro bind *:80 do HAProxy para um valor diferente de por exemplo site1.domain.com:80. Esta condição server somente se não houver múltiplos sites.
Ajustar o arquivo /etc/hosts com o nome de todos os websites que passaram pelo HAProxy
# vi /etc/hosts
127.0.0.1 localhost
111.11.1.1 site1.domian.com site1
111.11.1.1 site2.domian.com site2
Acesse o arquivo de configuração do haproxy:
# cd /etc/haproxy/
# cp -a haproxy.cfg haproxy.cfg.default
# cat haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats socket /run/haproxy/info.sock mode 660 level user
stats timeout 30s
user haproxy
group haproxy
daemon
maxconn 4096
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000 #outra opcao 5s
timeout client 50000 #30s
timeout server 50000 #30s
timeout http-request 10s # Protege contra ataques de leitura lenta
timeout http-keep-alive 2s
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen stats
bind *:8404
stats enable
stats uri /monitor
stats refresh 5s
stats auth admin:SuaSenhaMuitoForteAqui
acl network_allowed src 10.1.10.0/24
http-request deny if !network_allowed
frontend http-in
bind *:80
# Segurança de Cabeçalhos HTTP
http-response set-header X-Frame-Options "SAMEORIGIN"
http-response set-header X-Content-Type-Options "nosniff"
http-response set-header Referrer-Policy "no-referrer-when-downgrade"
# Proteção contra Ataques de Negação de Serviço (DoS/DDoS)
# Tabela para rastrear IPs por 30 segundos
stick-table type ip size 100k expire 30s store http_req_rate(10s)
# Bloqueia se o IP fizer mais de 100 requisições em 10 segundos
http-request track-sc0 src
http-request deny deny_status 429 if { sc0_http_req_rate gt 100 }
default_backend nodes-http-in
backend nodes-http-in
balance roundrobin # leastconn,source,uri,url_param,hdr(name)
server SRV1 10.1.10.151:80 check
server SRV2 10.1.10.152:80 check
### http-response set-header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Testar se o arquivo de configuração esta valido
# haproxy -c -f /etc/haproxy/haproxy.cfg
Configuration file is valid
Reinicie para validar as configurações
# systemctl restart haproxy.service