This Docker image is built on the official nginx:latest base image and extends it with the dynamic GeoIP2 module (ngx_http_geoip2_module), enabling real-time geolocation lookups of incoming client IP addresses using MaxMind GeoIP2 databases. It is suitable for scenarios that require IP-based geolocation, access control, traffic analysis, or region-specific content delivery.
nginx:latest image as the runtime foundation.build-essential, libpcre2-dev, zlib1g-dev, libssl-dev, libmaxminddb-dev, and mmdb-bin, then cleans up the apt cache to reduce image size.ngx_http_geoip2_module source from its GitHub repository.--with-compat and the GeoIP2 dynamic module, then runs make modules to compile the module as a loadable .so file.ngx_http_geoip2_module.so into /etc/nginx/modules/ and removes temporary archives to keep the image lean.The following MaxMind GeoIP2 database files are copied into /etc/nginx/geoip2/:
| File | Description |
|---|---|
GeoLite2-City.mmdb | City-level geolocation database |
GeoLite2-Country.mmdb | Country-level geolocation database |
GeoLite2-ASN.mmdb | Autonomous System Number database |
CountryOnly.mmdb | Custom country-only database |
qqwry.mmdb | Chinese IP location database (QQWry format) |
These databases can be referenced in nginx.conf via the geoip2 directive to map client IPs to country, city, and ASN data.
The bundled nginx.conf (/etc/nginx/nginx.conf) includes the following key settings:
auto to match the number of CPU cores; worker_connections is 1024.server_tokens off hides the Nginx version for security.client_max_body_size 5G allows large file uploads.server_name _) returns 403 for all requests, forcing access via configured domain names/virtual hosts./etc/nginx/conf.d/*.conf.stream block includes /etc/nginx/conf.d/*.stream, enabling raw TCP proxying (e.g., for non-HTTP protocols).X-Forwarded-For support; stream access logging is disabled.80 (HTTP) and 443 (HTTPS).nginx -g 'daemon off;' — runs Nginx in the foreground, as required by Docker.Place custom virtual host configs in /etc/nginx/conf.d/ and TCP stream configs in /etc/nginx/conf.d/ with a .stream extension.
The GeoIP2 module is compiled and installed in /etc/nginx/modules/, but it is not loaded by the default nginx.conf. You must manually add the load_module directive at the top level and reference a GeoIP2 database inside the http block (e.g., in /etc/nginx/conf.d/ or by editing nginx.conf) to activate it:
load_module modules/ngx_http_geoip2_module.so;
http {
geoip2 /etc/nginx/geoip2/GeoLite2-City.mmdb {
$geoip2_country_code country iso_code;
$geoip2_city_name city names en;
}
}
Keep the GeoIP2 databases up to date by replacing the .mmdb files; they are not automatically refreshed.
Content type
Image
Digest
sha256:0f3a2d8bf…
Size
229 MB
Last updated
4 days ago
docker pull qida/nginx