Hi,
On Tue, Feb 28, Simon Green wrote:
> I need to rate limit users by country[1], and my Google foo is failing
> me. I know that I can use "src_conn_rate gt N"[2], but that rate limits
> on a per IP basis. I want to be able to rate limit based on the total
> number of connections from a country, and have different limits for
> different countries.
My example uses sc0_conn_rate, but if you want to count number of
connections then you'll probably want to use conn_cnt.
> Is this possible with HAProxy, and if so, how?
There are probably better ways of doing this, but this is a quick
and dirty example. Needs acls etc. to use different conn_rate for
different geoip country.
(example acl:
acl geo_FI src,map_ip(geoip.map) -m str FI
acl FI_rate sc0_conn_rate gt 3
http-request deny if geo_FI FI_rate
(I don't know if it makes noticeable difference to use
src,map_ip -m str FI vs. src -f FI.lst in acl)).
geoip.map file (made up example):
127.0.0.0/8 NZ
10.0.0.0/8 FI
192.168.0.0/16 UK
# You'll need to use a script+iprange to convert maxmind geoip files to
# this kind of map file.
frontend testgeo
bind [email protected]:8086
tcp-request inspect-delay 8s
http-request track-sc0 src,map_ip(geoip.map) table table1 if {
src,map_ip(geoip.map) -m found }
http-request deny if { sc0_conn_rate gt 5 }
default_backend somebackend
backend table1
# len 4 should cover two char country code
# size 128 how many possible country codes
stick-table type string len 4 size 128 expire 240s store conn_rate(30s)
-Jarno
--
Jarno Huuskonen