Maxmind GeoIp2 and Nginx on Ubuntu 16.04

Nginx full package by default has GeoIp module, install Maxmind GeoIp2 is a little more complicated, so let’s begin

Requirements: Fresh new install Ubuntu 16.04

Adding Maxmind libraries

Installing Maxmind  libraries

Adding official Nginx repositories

Installing nginx

The Debian package provided by ppa:nginx/stable sets up configuration to monitor and start Nginx on system boot (Upstart/SysInit), logrotate and other system needs. These are things we would otherwise need to setup manually. We don’t want to skip these by installing from source!

The next steps are:

  1. Get the sources/dependencies used to
  2. Add our modules to the ppa:nginx/stable package
  3. Rebuild the packages
  4. Re-install Nginx

Adding folders to work on

Geoip2 folder

Check if source repository is uncommented

If not, change it to

Installing building dependencies

Nginx folder to work on

Get Nginx (ppa:nginx/stable) source files

Install the build dependencies

Installing some required dependencies

Checking Nginx folder

To adjust add the modules into the build, edit the /opt/rebuildnginx/nginx-1.12.2/debian/rules file.

The ppa:nginx/stable has multiple Nginx packages available: common, light, full and extras. When you run apt-get install -y nginx, you’re installing the “full” version.

The “common” package is the base install upon which the others are built. The “lighter” package, however is in fact lighter than the “common” package due to the use of the –without-* flags.

For this example, simply edit the “full” version to add the module. This assumes to keep using the “full” package as normal when installing Nginx.

From the rules file, here’s the “full” version configuration with the module added at the end:

Once that’s edited and saved, build Nginx!

Once the build is complete, we’ll find a bunch of .deb files added in /opt/rebuildnginx. We can use these to install Nginx.

We adjusted the “full” package, and so we’ll want to use that build to install Nginx. Looking at the deb files, we’ll see two “full” packages

Check the module compiled on the output from

Add this line on nginx.conf before events{…} section

Inside http{…} section add the following

Add the variables to fastcgi_params files file

Restart nginx

NOTE: This could be done with any other extra module for Nginx

Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 7 =

%d bloggers like this: