important note: this vmod is now obsolete (as libgeoip itself is) and won't receive updates.
Author: | Hauke Lampe |
---|---|
Date: | 2011-09-26 |
Version: | 1.0.3 |
Manual section: | 3 |
import geoip;
This Varnish module exports functions to look up GeoIP country codes. Requires GeoIP library (on Debian install libgeoip-dev)
Inspired by https://vrobert.fr/2010/07/another-way-to-link-varnish-and-maxmind-geoip/
- Prototype
ip_country_code(IP I)
- Return value
- STRING
- Description
- Returns two-letter country code string from IP address
- Example
set req.http.X-Country-Code = geoip.ip_country_code(client.ip);
- Prototype
country_code(STRING S)
- Return value
- STRING
- Description
- Returns two-letter country code string
- Example
set req.http.X-Country-Code = geoip.country_code("127.0.0.1");
- Prototype
ip_country_name(IP I)
- Return value
- STRING
- Description
- Returns country name string from IP address
- Example
set req.http.X-Country-Name = geoip.ip_country_name(client.ip);
- Prototype
country_name(STRING S)
- Return value
- STRING
- Description
- Returns country name string
- Example
set req.http.X-Country-Name = geoip.country_name("127.0.0.1");
- Prototype
ip_region_name(IP I)
- Return value
- STRING
- Description
- Returns region name string from IP address
- Example
set req.http.X-Region-Name = geoip.ip_region_name(client.ip);
- Prototype
region_name(STRING S)
- Return value
- STRING
- Description
- Returns region name string
- Example
set req.http.X-Region-Name = geoip.region_name("127.0.0.1");
The source tree is based on autotools to configure the building, and does also have the necessary bits in place to do functional unit tests using the varnishtest tool.
It is a prerequisite that you have the varnish-dev package installed as well as varnish:
apt-get install varnish-dev
Install the GeoIP library headers:
apt-get install libgeoip-dev
To check out the current development source:
git clone git://github.com/varnish/libvmod-geoip.git cd libvmod-geoip; ./autogen.sh
Usage:
./configure
Make targets:
- make - builds the vmod
- sudo make install - installs your vmod
- make check - runs the unit tests in
src/tests/*.vtc
Certain versions of the GeoIP library will fail if the GeoIP database file is updated by overwriting the old file directly.
This could impact varnish stability, and it is therefore recommended
to download the update as a new file, and then mv
the new file
onto the old active database.