-
Notifications
You must be signed in to change notification settings - Fork 4
/
haproxy_example.cfg
42 lines (33 loc) · 1.54 KB
/
haproxy_example.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
defaults
option httplog
mode http
log stdout format raw local0
global
lua-load /tmp/haproxy_geoip_lookup.lua
frontend test_country
bind :6969
# skip lookup for non-global ips (could be extended to bogons)
acl private_nets src 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 127.0.0.0/8 ::1
http-request set-var(txn.geoip_country) str(00) if private_nets
# lookup from database
http-request lua.lookup_geoip_country if !{ var(txn.geoip_country) -m found }
# log it
http-request capture var(txn.geoip_country) len 2
http-request deny status 200
frontend test_country_cachemap
# Cache IPs in memory-map for faster lookups
# NOTE: maps are cleared on reload/restart
bind :6979
# skip lookup for non-global ips (could be extended to bogons)
acl private_nets src 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 127.0.0.0/8 ::1
http-request set-var(txn.geoip_country) str(00) if private_nets
# lookup from memory
acl geoip_country_in_map src,ipmask(24,48),map_ip(/tmp/haproxy_geoip_country.map) -m found
http-request set-var(txn.geoip_country) src,ipmask(24,48),map(/tmp/haproxy_geoip_country.map) if !private_nets geoip_country_in_map
# lookup from database
http-request lua.lookup_geoip_country if !{ var(txn.geoip_country) -m found }
# log it
http-request capture var(txn.geoip_country) len 2
# write to map
http-request set-map(/tmp/haproxy_geoip_country.map) %[src,ipmask(24,48)] %[var(txn.geoip_country)] if !private_nets !geoip_country_in_map
http-request deny status 200