如何在 HAProxy 中阻止 IP 地址?

如何在 HAProxy 中阻止 IP 地址?

haproxy 中是否有类似 Apache “deny from ip” 的功能?

答案1

您可以通过创建 ACL 并在 ACL 匹配时使用连接拒绝来在 tcp 级别删除 IP:

    acl bad_ip src 10.10.10.0
    tcp-request connection reject if bad_ip

如果您想在 HTTP 级别执行此操作,您还可以设置 403 后端并将它们发送到该后端:

frontend foo
        ...
        acl bad_ip src 10.10.10.0
        use_backend bad_guy if bad_ip
...

backend bad_guy
        mode http
        errorfile 403 /etc/haproxy/errors/403.http

这些 ACL 非常灵活,您可以让一个 ACL 中的多个条件或操作中的多个 ACL 得到满足。更多信息请访问http://haproxy.1wt.eu/download/1.5/doc/configuration.txt

相关内容