限制 HAProxy 上特定路径的最大请求数/秒

Bas*_*974 2 haproxy rate-limiting

我正在尝试实现这种情况:

仅在特定路径上,我在前端收到稳定的 9 个请求/秒。一切都很好,使用常规后端。我现在收到 11 req/s,我想拒绝任何超过 10 的请求。但仍然想继续回复最大 10 req/sec。

我发现并尝试实现的所有内容(如下所示:https : //blog.codecentric.de/en/2014/12/haproxy-http-header-rate-limiting/)都是黑色或白色的解决方案,一旦率达到。所以它是一种防止 DDOS、滥用者的保护,但不是真正的速率限制解决方案。

有什么方法可以实现吗?
PS:使用 HAproxy 1.5.8

小智 6

如果您想使用rate-limit sessions,以下对您是否可行?

frontend http_in
   bind 0.0.0.0:80
   acl is_path url_beg /path/example/
   use_backend forwarder if is_path

backend forwarder
   server localhost 127.0.0.1:4444 send-proxy

frontend limit_path_backend
   bind 127.0.0.1:4444 accept-proxy
   rate-limit sessions 10
   default_backend webnodes
Run Code Online (Sandbox Code Playgroud)