Skip to content
Federico G. Schwindt edited this page Apr 13, 2017 · 27 revisions

Welcome to the libvmod-geoip2 wiki!

Examples

Please note you need to supply the full path for the mmdb file, e.g. /var/db/maxmind/GeoLite2-Country.mmdb.

Pass the ISO code to the backend servers

import geoip2;

sub vcl_init {
    new country = geoip2.geoip2("GeoLite2-Country.mmdb");
}

sub vcl_recv {
    set req.http.X-Country-Code = country.lookup("country/iso_code", client.ip);
}	

Pass the ISO code to the backend servers using the first X-Forwarded-For IP if supplied

import geoip2;

sub vcl_init {
    new country = geoip2.geoip2("GeoLite2-Country.mmdb");
}

sub vcl_recv {
    set req.http.X-Country-Code = country.lookup("country/iso_code", 
        std.ip(regsub(req.http.X-Forwarded-For, "^(\d+\.\d+\.\d+\.\d+).*", "\1"), 
            client.ip));
}
Clone this wiki locally