haproxy-geoip2

Crates.iohaproxy-geoip2
lib.rshaproxy-geoip2
version0.2.0
created_at2025-02-07 17:54:11.2494+00
updated_at2025-07-17 18:57:29.966504+00
descriptionHAProxy MaxMind GeoIP2 support
homepage
repositoryhttps://github.com/khvzak/haproxy-geoip2
max_upload_size
id1547249
size39,355
Alex Orlenko (khvzak)

documentation

README

haproxy-geoip2

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.

Usage

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)]\"}"

License

This project is licensed under the MIT license

Commit count: 4

cargo fmt