| Crates.io | haproxy-geoip2 |
| lib.rs | haproxy-geoip2 |
| version | 0.2.0 |
| created_at | 2025-02-07 17:54:11.2494+00 |
| updated_at | 2025-07-17 18:57:29.966504+00 |
| description | HAProxy MaxMind GeoIP2 support |
| homepage | |
| repository | https://github.com/khvzak/haproxy-geoip2 |
| max_upload_size | |
| id | 1547249 |
| size | 39,355 |
haproxy-geoip2 adds MaxMind GeoIP database support to HAProxy 2.8+ Community Edition using Lua API.
It implemented as a native Lua module written in Rust using mlua and haproxy-api crates.
Please check the module and tests directories for working examples.
local geoip2 = require("haproxy_geoip2_module")
geoip2.register({
-- Only City and ASN databases are supported yet
db = {
city = "data/GeoIP2-City-Test.mmdb",
asn = "data/GeoLite2-ASN-Test.mmdb",
},
-- How often to reload the database files in seconds
-- if set to 0, the database files will only be loaded once (at startup)
reload_interval = 86400,
})
The module registers the following converters in HAProxy:
global
master-worker
# If reload_interval is set to a value greater than 0,
# this option is required to enable non-blocking databases loading
insecure-fork-wanted
lua-load-per-thread haproxy.lua
...
listen http-in
bind *:8080
http-request set-var(txn.city) url_param(ip),lua.geoip2-lookup-city("city","names","en")
http-request set-var(txn.asn) url_param(ip),lua.geoip2-lookup-asn("asn")
http-request return status 200 content-type text/plain lf-string "{\"city\":\"%[var(txn.city)]\",\"asn\":\"%[var(txn.asn)]\"}"
This project is licensed under the MIT license