C Library
PHP Module
Perl Module
Ruby Library
Python Library
Apache Module
Nginx Module
Node.js Module
Cocoa / Objective C Library
Pascal Library
D Library
Go Package
Erlang Module
Haskell Package
Debian Package
Lua Package
Kotlin Module
Scala Library
OpenResty Package
Splunk Add-on
Apache Kafka Transform
OCaml Module
Deno Module
R Package
.NET Component
Java Component
HTTP Module
ActiveX / COM DLL
IP2Location IP Geolocation Nginx Module
This is an IP2Location IP Geolocation 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 C library from here.
- Download and decompress this Nginx module package.
- Change the path to IP2Location library in "ngx_http_ip2location_module.c".
- 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-master make make install
- Edit your Nginx config file (nginx.conf), add the following lines under `http` context:
http { ... ip2location_database /usr/share/ip2location/DB6.BIN; ip2location_proxy_recursive on; ip2location_proxy 192.168.1.0/24; }
Block visitors from China:
if ( $ip2location_country_short = "CN" ) {
return 403;
}
Redirect visitors from Canada, United States, and Mexico to new page:
if ( $ip2location_country_short ~* "CA|US|MX" ) {
rewrite ^ http://example.com/newpage.html permanent;
}
-
ngx-ip2location
This is a IP2Location Nginx Module that enables the user to identify the country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, area code and weather by IP address.
You can always refer to our blog for the articles and tutorials about IP2Location NginX module.
Discover Your User Locations
Retrieve geolocation data for FREE now!