Nginx with GeoIP2 as dynamic module based on official Nginx images (Alpine and Debian)
10K+
1.19.2-geoip2-3.3, mainline, latest1.19.2-alpine-geoip2-3.3, mainline-alpine1.18.0-geoip2-3.3, stable1.18.0-alpine-geoip2-3.3, stable-alpineTag syntax : {nginx-tag}-{module_name}-{module_version}
This images doesn't contains any configuration except the load_module directive in the main nginx configuration file.
If you want to use it, i'ts mandatory to have a geo database in MMDB format. You can found free databases here :
Download DB-IP IP to country database :
wget https://download.db-ip.com/free/dbip-country-lite-2020-08.mmdb.gz
gunzip dbip-country-lite-2020-08.mmdb.gz
Extract nginx.conf
docker run --rm anroe/nginx-geoip2:1.19.2-alpine-geoip2-3.3 cat /etc/nginx/nginx.conf > nginx.conf
Edit extracted nginx.conf and add the following in http block
geoip2 /etc/nginx/dbip-country-lite-2020-08.mmdb {
$geoip2_data_country_code default=US source=$http_x_forwarded_for country iso_code;
}
add_header X-Country-Code "$geoip2_data_country_code" always;
Run the container
docker run --name nginx-geoip2 --rm \
-p 8080:80 \
-v /path/to/dbip-country-lite-2020-08.mmdb:/etc/nginx/dbip-country-lite-2020-08.mmdb \
-v /path/to/nginx.conf:/etc/nginx/nginx.conf \
anroe/nginx-geoip2:1.19.2-alpine-geoip2-3.3
Execute the following curl command
curl -s -I --header "X-Forwarded-For: $(dig +short myip.opendns.com @resolver1.opendns.com)" localhost:8080 | grep Country
Your own country code should be displayed.
You can use the GeoIP2 module compiled in this image in your own image.
At the beginning of nginx.conf :
load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so;
In your Dockerfile :
RUN apt-get update && apt-get install -y libmaxminddb0
COPY --from=anroe/nginx-geoip2:1.19.2-geoip2-3.3 /usr/lib/nginx/modules/ngx_http_geoip2_module.so /usr/lib/nginx/modules/ngx_http_geoip2_module.so
In your Dockerfile :
RUN apk add --no-cache --update libmaxminddb
COPY --from=anroe/nginx-geoip2:1.19.2-alpine-geoip2-3.3 /usr/lib/nginx/modules/ngx_http_geoip2_module.so /usr/lib/nginx/modules/ngx_http_geoip2_module.so
https://github.com/leev/ngx_http_geoip2_module
Content type
Image
Digest
Size
51.4 MB
Last updated
about 6 years ago
docker pull anroe/nginx-geoip2