How To Install Nginx With GeoIP Module


In this tutorial, we will show you how to install and configuration of Nginx With GeoIP Module on your Linux server. For those of you who didn’t know, Nginx GeoIP module for country and city geo-targeting can be installed in a few easy steps. It brings you a geo-targeting layer allowing you to show some parts of your websites, or even split traffic according to the geographical location of the end-users. By default, when you install modules from yum, Nginx will not come with GeoIP module (This is the module: HttpGeoipModule), so we will install from source and the active the module.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation and configure Nginx with GeoIP module on CentOS 6.

Install Nginx With GeoIP Module

Step 1. The first install requires a package for compiling:

Step 2. Download the latest stable version of Nginx from here and build it with GeoIP module support.

Step 3. Create an init script for Nginx.

Step 4. Finally, start the Nginx.

Step 5. Install GeoIP library via yum

After successful installation, the library will be stored in/usr/share/GeoIP/GeoIP.dat For the latest updates can be downloaded here.

Configure Nginx

  • Configure on the main file:
  • Configure Nginx virtual host:

The above configuration will accept all IP and banned only from China IP (CN). About Code of the country in GeoIP database you can refer here:

Congratulation’s! You have successfully installed Nginx With GeoIP Module. Thanks for using this tutorial for installing Nginx With GeoIP Module on Linux system. For additional help or useful information, we recommend you to check the official Nginx web site.

Nginx Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “Nginx Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get a best deal!