Limit maximum requests / second for a specific path on HAProxy
10,060
If you want to use rate-limit sessions
, is the following feasible for you?
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
Related videos on Youtube
Author by
Bastien974
Updated on September 18, 2022Comments
-
Bastien974 almost 2 years
I'm trying to achieve this scenario :
On a specific path only, I receive a steady 9 requests/sec on the frontend. Everything is fine, use the regular Backend. I now receive 11 req/s, I want to reject any requests above 10. But still want to continue replying to a maximum of 10 req/sec.
Everything I have found and tried implementing (like this : https://blog.codecentric.de/en/2014/12/haproxy-http-header-rate-limiting/), are black or white solution, it drops everything once the rate is reached. So it's a protection against DDOS, abuser, but not a real rate limiting solution.
Is there any way to achieve that ?
PS: using HAproxy 1.5.8-
GregL almost 9 yearsOr by using
rate-limit sessions <rate>
(docs) in the frontend. -
Bastien974 almost 9 yearsSorry, I forgot to add an important requirement, I need to limit just a specific path, not frontend wide.
maxconnrate
is a global setting and wouldn't work for me.rate-limit sessions
does what I want but is frontend-wide.
-