我试图通过使用haproxy ACL和-f选项来拒绝来自特定用户代理的连接(通过匹配user-agent头的子string)从文件读取。 然而,它不工作,它运行,如configuration被忽略。
有没有更好的经验与haproxy找出我失踪? 或者关于如何debugging这个haproxyconfiguration的一些提示?
我正在运行haproxy 1.4.18。
这是haproxy.cfg的摘录:
listen http 0.0.0.0:80 acl abuser hdr_sub(user-agent) -f /etc/haproxy/abuser.lst tcp-request content reject if abuser mode http server www1 127.0.0.1:8080 maxconn 10000
这是abuser.lst文件的内容:
# annoying bots annoyingbot1 annoyingbot2
这个问题很古老,但如果有人遇到这个问题:
您的问题来自tcp-request content在HAProxy有时间接收/读取任何第7层数据之前运行的事实。
如何解决这个问题?
简单:添加一个tcp-request检查延迟 :
listen http 0.0.0.0:80 tcp-request inspect delay 15s acl abuser hdr_sub(user-agent) -f /etc/haproxy/abuser.lst tcp-request content reject if abuser mode http server www1 127.0.0.1:8080 maxconn 10000
以下是HAProxy文档中的重要内容:
请注意,在进行内容检查时,haproxy会根据这些数据是不完整的事实来评估每个进入的新块的整体规则。 如果在上述延迟之前没有规则匹配,则在到期时执行最后的检查,这次考虑到内容是确定的。 如果没有延迟,haproxy将不会等待,并立即根据可用的信息作出判决 。 显然这不太可能是非常有用的,甚至可能是活泼的,所以不build议这样的设置。