All Projects → ip2location → ip2location-nginx

ip2location / ip2location-nginx

Licence: MIT license
This is IP2Location Nginx module that enables the user to find the country, region (state), city, latitude, longitude, zip code, time zone, ISP, domain name, connection type, area code, weather, mobile network, elevation, usage type, address type and IAB category by IP address or hostname originates from.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to ip2location-nginx

ip2location-piwik
Use IP2Location geolocation database to lookup for accurate visitor location in Matomo (Piwik) 3.x. It enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, address type and IAB category that any IP address o…
Stars: ✭ 26 (-31.58%)
Mutual labels:  geolocation, ip-lookup, ip-geolocation, ip2location, ip-database
ip2location-cakephp
IP2Location CakePHP plugin enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, IP address type and IAB advertising category from IP address using IP2Location database.
Stars: ✭ 17 (-55.26%)
Mutual labels:  geolocation, ip-lookup, ip-geolocation, ip2location, ip-database
IP2Country
Ip to country mapping
Stars: ✭ 39 (+2.63%)
Mutual labels:  geolocation, ip-lookup, ip-geolocation, ip2location
ip2location-csv-converter
This PHP script converts IP2Location CSV database into IP range or CIDR format.
Stars: ✭ 26 (-31.58%)
Mutual labels:  geolocation, ip-geolocation, ip2location
IP2Location-C-Library
IP2Location C library enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather station code, weather station name, mobile, usage types, etc that any IP address or hostname originates from.
Stars: ✭ 37 (-2.63%)
Mutual labels:  geolocation, ip-lookup, ip2location
ip2location-iata-icao
This list contains the airport codes of IATA airport code and ICAO airport code together with country code and region name supported in IP2Location geolocation database.
Stars: ✭ 39 (+2.63%)
Mutual labels:  geolocation, ip-geolocation, ip2location
ip2location-lua
Use IP2Location geolocation database to lookup the geolocation information with IP2Location Lua Package. It can be used to determine country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, address type and IAB category that any IP address …
Stars: ✭ 14 (-63.16%)
Mutual labels:  geolocation, ip-geolocation, ip2location
ipapi-python
Python bindings for https://ipapi.co (IP Address Location) - Use with python / django / flask for IP address location lookup
Stars: ✭ 42 (+10.53%)
Mutual labels:  geolocation, ip-lookup, ip-geolocation
ip2location-nginx
Nginx module that allows user to lookup for geolocation information using IP2Location database.
Stars: ✭ 33 (-13.16%)
Mutual labels:  geolocation, ip-lookup, ip2location
IP2Location-PHP-Module
This module is a PHP module that enables the user to find the country, region, city, coordinates, zip code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, mobile, usage types, address type, IAB category, etc that any IP address or host name originates from.
Stars: ✭ 154 (+305.26%)
Mutual labels:  geolocation, ip-lookup, ip2location
ruby
Official Ruby client library for IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 42 (+10.53%)
Mutual labels:  ip-geolocation, ip-database
ipinfodb-php
PHP library to query free IPInfoDB API service.
Stars: ✭ 15 (-60.53%)
Mutual labels:  geolocation, ip2location
Freegeoip
IP geolocation web server
Stars: ✭ 4,812 (+12563.16%)
Mutual labels:  geolocation, ip-database
mmdb-server
mmdb-server is an open source fast API server to lookup IP addresses for their geographic location.
Stars: ✭ 69 (+81.58%)
Mutual labels:  geolocation, ip-geolocation
geolocation
A laravel integration for using the IPInfoDB and Ip2Location services
Stars: ✭ 38 (+0%)
Mutual labels:  geolocation, ip2location
WordPress-IP-Geo-Block
A WordPress plugin that will blocks any comment, pingback and trackback spams posted from outside your nation. And it will also protect against malicious access to the login form, admin area and XML-RPC from undesired countries.
Stars: ✭ 26 (-31.58%)
Mutual labels:  ip-geolocation, ip2location
cli
Official Command Line Interface for the IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 1,279 (+3265.79%)
Mutual labels:  ip-lookup, ip-geolocation
ip-location-db
ip to location database by ASN, GeoFeed, Whois, iptoasn.com, db-ip lite, GeoLite2
Stars: ✭ 160 (+321.05%)
Mutual labels:  ip-geolocation, ip2location
django
Official Django Library for IPinfo API (IP geolocation and other types of IP data)
Stars: ✭ 36 (-5.26%)
Mutual labels:  ip-geolocation, ip-database
Geolocate-IP-Browser-Extension
A browser extension, which shows you the origin of your IP address.
Stars: ✭ 21 (-44.74%)
Mutual labels:  geolocation, ip-geolocation

Nginx IP2Location module

Description

The Nginx IP2Location module enables user to easily perform client's IP to geographical location lookup by using IP2Location database.

The IP2Location database can be downloaded from https://lite.ip2location.com (Free) or https://www.ip2location.com (Commercial).

Installation

  1. Download IP2location C library from https://github.com/chrislim2888/IP2Location-C-Library

  2. Compile and install IP2Location C library.

  3. Download IP2Location module and decompress the package.

    wget https://github.com/ip2location/ip2location-nginx/archive/master.zip
    unzip master.zip
    rm master.zip
  4. Download the latest Nginx source code from https://nginx.org/en/download.html

    wget https://nginx.org/download/nginx-x.y.z.tar.gz
  5. Decompress and go into Nginx source directory.

    tar xvfz nginx-x.y.z.tar.gz
    cd nginx-x.y.z
  6. Re-compile Nginx from source to include this module.

    Static Module

    ./configure --add-module=/absolute/path/to/nginx-ip2location-master
    make
    make install

    Dynamic Module

    ./configure --add-dynamic-module=/absolute/path/to/nginx-ip2location-master
    make
    make install

Nginx Configuration

Insert the configuration below to your nginx.conf.

Syntax      : load_module modules/ngx_http_ip2location_module.so;
Default     : -
Context     : main
Description : Load IP2Location Nginx module if it was compiled as dynamic.
Syntax      : ip2location_database path
Default     : none
Context     : http
Description : The absolute path to IP2Location BIN database.
Syntax      : ip2location_proxy_recursive on|off
Default     : off
Context     : http
Description : Enable recursive search in the x-forwarded-for headers.
Syntax      : ip2location_proxy cidr|address
Default     : none
Context     : http
Description : Set a list of proxies to translate x-forwarded-for headers for.

Example:

http {
	...
	
	ip2location_database		/usr/share/ip2location/DB6.BIN;
	ip2location_proxy_recursive	on;
	ip2location_proxy		192.168.1.0/24;
}

Variables

The following variables will be made available in Nginx:

$ip2location_country_short
$ip2location_country_long
$ip2location_region
$ip2location_city
$ip2location_isp
$ip2location_latitude
$ip2location_longitude
$ip2location_domain
$ip2location_zipcode
$ip2location_timezone
$ip2location_netspeed
$ip2location_iddcode
$ip2location_areacode
$ip2location_weatherstationcode
$ip2location_weatherstationname
$ip2location_mcc
$ip2location_mnc
$ip2location_elevation
$ip2location_usagetype
$ip2location_addresstype
$ip2location_category

Usage Example

Add Server Variables
server {
	listen 80 default_server;
	root /var/www;
	index index.html index.php;

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	server_name _;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		fastcgi_pass php-fpm-sock;
		fastcgi_index index.php;
		include fastcgi.conf;

		# Add custom header to view result in HTTP response
		add_header X-Country-Code $ip2location_country_short;
		add_header X-Country-Name $ip2location_country_long;

		fastcgi_param IP2LOCATION_COUNTRY_SHORT       $ip2location_country_short;
		fastcgi_param IP2LOCATION_COUNTRY_LONG        $ip2location_country_long;
		fastcgi_param IP2LOCATION_REGION              $ip2location_region;
		fastcgi_param IP2LOCATION_CITY                $ip2location_city;
		fastcgi_param IP2LOCATION_ISP                 $ip2location_isp;
	}
}

Notes: Restart Nginx and view your server response header to confirm the variables are added.

Block Single Country
if ( $ip2location_country_short = 'US' ) {
    return 444;
}
Block Multiple Countries
map $ip2location_country_short $blacklist_country {
	default no;
	AU yes;
	IN yes;
	NG yes;
}

server {
    ...
        
	if ( $blacklist_country = yes ) {
		return 444;
	}
}

IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses.

If you query an IPv6 address using the IPv4 BIN, you'll see the INVALID_IP_ADDRESS error.

Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

Support

Please visit us at https://www.ip2location.com for services and databases we offer.

For support, please email us at [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].