Skip to main content

Command Palette

Search for a command to run...

How To Block IP Addresses In HAProxy

Published
1 min read
How To Block IP Addresses In HAProxy

Update haproxy.cfg to add condition acl is-blocked-ip src -f /etc/haproxy/blocklisted.ips

frontend fe-lehaproxy
        bind *:80

        acl is-blocked-ip src -f /etc/haproxy/blocklisted.ips
        http-request deny if is-blocked-ip

        acl letsencrypt-acl path_beg /.well-known/acme-challenge/
        use_backend letsencrypt-backend if letsencrypt-acl
        redirect scheme https code 301 if !letsencrypt-acl

frontend fe-verify
        bind *:443 ssl crt /etc/certs

        acl is-blocked-ip src -f /etc/haproxy/blocklisted.ips
        http-request deny if is-blocked-ip

        http-request set-header X-Forwarded-Proto https if { ssl_fc }
        default_backend mybackend

Blocked list

~:/etc/haproxy# cat blocklisted.ips 
32.66.111.255
11.129.81.18

Requests from IP addresses within the blocklisted.ips file will receive 403 Alt Text

Another way to block IP addresses is to update inbound rule of AWS ALC Alt Text

More about HAProxy

More from this blog

V

Vu Dao

102 posts

🚀 AWSome Devops | AWS Community Builder | AWS SA || ☁️ SimflexCloud ☁️

How To Block IP Addresses In HAProxy