I am trying to solving a scenario now using haproxy. The scenario as below
- Block all IP by default
- Allow only connection from a specific IP address
- If any connections come from a whilelist IP, if should reject if it exceed more than 10 concurrent connection in 30 sec
I want to do this to reduce number of API calls into my server. Could any one please help me with this?
Thanks
First two things are easy, simply allow only whitelisted IP
The third - throttling - requires to use stick-tables (there are many data type - counters conn, sess, http, rates...) as a rate counter:
next you have to fill the table, by tracking each request eg. by IP
and finally the acl:
For example some working config file with customized errors:
Note: the error handling is a bit tricky. Because above error backends are missing server entries, haproxy will throw HTTP 503,
errorfile
catch them and send different errors (with different codes).Example
/etc/haproxy/errors/401.http
content:Example
/etc/haproxy/errors/429.http
content: