Bringing Location to the Internet
   

Nginx Module

This is an IP2Location Nginx Module that enables the user to identify the country code and country name by IP address. In general, it is faster, easier and more accurate than reverse DNS lookups.

Download IP2Location Nginx Module (3.35 kB) Version: 1.0

 

Installation
  1. Download IP2location C library from here.
  2. Download and decompress this Nginx module package.
  3. Change the path to IP2Location library in "ngx_http_ip2location_module.c".
  4. Re-compile Nginx from source to include this module. Add the below directive into the compile of Nginx:
    ./configure --add-module=/absolute/path/to/nginx-ip2location-1.0
  5. make
  6. make install
  7. Edit your Nginx config file to point the correct path of IP2Location database file:
    ip2location_database /absolute/path/to/IP2LOCATION-DB1.BIN;

 

Sample Codes

Block visitors from China:

if ( $ip2location_country_code = "CN" ) {
	return 403;
}

 

Redirect visitors from Canada, United States, and Mexico to new page:

if ( $ip2location_country_code ~* "CA|US|MX" ) {
	rewrite ^ http://example.com/newpage.html permanent;
}

 

Sample Database (BIN)

Evaluation version of the database file having limited range of IP address information. You can query all IP addresses from 0.0.0.0 to 99.255.255.255 only.