GeoNames.org for GeoIP2 checks
Daniel Nashed – 14 November 2026 22:32:13
The NGINX NRPC container image got GeoIP2 support a couple of weeks ago.
GeoIP data can be used for logging and to only allow access from certain locations or networks.
Beside the GeoIP2 data you might need information about Countries, Regions, Cities and more.
There is an interesting database which also provides an API.
https://www.geonames.org/
The database is very interesting not just for browsing the needed geo codes.
Example: Hilden (my home town)
Example: Configuration for an NGINX stream
stream {
geoip2 ${GEOIP_DB_DIR}/GeoLite2-City.mmdb {
auto_reload 5m;
$geoip2_country_code country iso_code;
$geoip2_region_code subdivisions 0 iso_code;
}
geoip2 ${GEOIP_DB_DIR}/GeoLite2-ASN.mmdb {
auto_reload 5m;
$geoip2_asn autonomous_system_number;
}
map "$geoip2_country_code:$geoip2_asn:$geoip2_region_code" $admin_allowed {
"DE:3320:NW" 1; # Telekom, North Rhine-Westphalia
default 0;
}
# Select backend by SNI
map $ssl_preread_server_name $admin_backend {
default 127.0.0.1:1;
k8s.example.com 192.168.20.10:6443;
}
# Reject connections that fail GeoIP/ASN checks
map $admin_allowed $filtered_backend {
0 127.0.0.1:1;
1 $admin_backend;
}
server {
listen 6443;
ssl_preread on;
proxy_connect_timeout 2s;
proxy_pass $filtered_backend;
}
}
- Comments [0]