Table of contents
GEO IP
-
Enable geo IP by adding new module in nginx
- Add a new module
--with-http_geoip_module
- nginx -V
check if this module is added
- Add a new module
- Adding the geo IP database from maxMind
mkdir /etc/nginx/geoip
- download from maxMind
- wget [download-able URL here]
- un-pack the database, saved in the directory
-
Configure
nginx.config
file- Add below inside http { … } block
geoip_country /etc/nginx/geoip/GeoIP.dat; geoip_city /etc/nginx/geoip/GeoLiteCity.dat;
Sample configuration
events { ... }
http {
include mine.type;
# Enabling Geo IP
geoip_country /etc/nginx/geoip/GeoIP.dat;
geoip_city /etc/nginx/geoip/GeoLiteCity.dat;
server {
listen 80;
server_name example.com;
root /var/www/example.com;
# Configuring Geo IP
location /geo_country {
return 200 "visisting from: $geoip_country_name";
# curl http://example.com/geo_country
}
location /geo_city {
return 200 ""visiting from: $geoip_city";
# curl http://example.com/geo_city
}
}
}