Installing the module

First, check if your build of nginx is already using the GeoIP module. Run the following command:

nginx -V

If the output contains


then you don’t have to do anything to install it. You just have to configure nginx to use it.

If it doesn’t contain


then you’ll have to build nginx yourself, passing




. For more information on building nginx, see this.

Configuring the module

Open your server configuration file and add the following to the http section:

geoip_country  /path/to/CountryGeoIP.dat
geoip_city     /path/to/GeoIPOrLiteCity.dat;



with the path to your GeoIP country database and replace


with the path to your GeoIP city database.

IMPORTANT: For the nginx module, you must provide both a country database and city database. If you just provide a city database, Matomo (Piwik) will not see any country information.

If you’re using an Organization or ISP database, you can add it to the config with:

geoip_org /path/to/GeoIPISPOrOrg.dat

Unfortunately, you can only supply one database here for the nginx module, so if you have both the ISP and Organization database, you will have to pick one to use.

Now make sure the following parameters are passed to fastcgi:

fastcgi_param GEOIP_ADDR $remote_addr;
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;

If you’re using a city database, add the following parameters:

fastcgi_param GEOIP_REGION $geoip_region;
fastcgi_param GEOIP_REGION_NAME $geoip_region_name;
fastcgi_param GEOIP_CITY $geoip_city;
fastcgi_param GEOIP_AREA_CODE $geoip_area_code;
fastcgi_param GEOIP_LATITUDE $geoip_latitude;
fastcgi_param GEOIP_LONGITUDE $geoip_longitude;
fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;

If you’re using an organization database, add the following parameters:

fastcgi_param GEOIP_ORGANIZATION $geoip_org;

Configuring the module on FreeBSD

If you use FreeBSD, or have an error such as unknown directive "geoip_country" in nginx.conf please check out the following blog post Loading the GeoIP Module with nginx 1.10.0 on FreeBSD

That’s all, folks. Enjoy!

Any questions?

Many answers and more information about Matomo you can find here:

We are social

Follow us: