Greetings,
On 08/26/2016 09:14 AM, Samrat Roy wrote:
Hello Sir,
down votefavorite
<http://stackoverflow.com/questions/39166887/haproxy-limiting-the-connection-rate-per-user#>
I am trying to achieve rate limiting using HAProxy. I am trying to
follow the "Limiting the connection rate per user" approach. I am able
to achieve this by the below configuration. But facing one problem,
that is, i am not able to send a custom error code once the rate limit
is reached. For example if i reached the rate limit i want to send
HTTP error code 429. In this case the proxy is simply rejecting the
incoming call and users are getting http status code as 0.
"tcp-request connection reject" rejects the connection, so there is no
status code in this case. If you want to send a 403 replace it with
"http-request deny if ..." instead.
If you want to respond with HTTP 429 make a backend with no backend
servers (so that all requests will get a 503) and set a custom 503 error
page, editing the headers at the top of the file so that the response
code is 429 (or whatever other code/message/etc you desire).
- Chad
Please let me know how can i do this
frontend localnodes
|bind *:80 mode http default_backend nodes stick-table type ip size
100k expire 30s store conn_rate(5s) tcp-request connection reject if {
src_conn_rate ge 60 } tcp-request connection track-sc1 src |
backend nodes
|cookie MYSRV insert indirect nocache server srv1 <Server IP>:80 check
cookie srv1 maxconn 500 |
Thanks
Samrat