Sign inSign up

anroe/nginx-geoip2

By anroe

•Updated almost 4 years ago

Nginx with GeoIP2 as dynamic module based on official Nginx images (Alpine and Debian)

Image
3

10K+

anroe/nginx-geoip2 repository overview

⁠Table of contents

⁠Tags

Tag syntax : {nginx-tag}-{module_name}-{module_version}

⁠How to use this image

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 :

⁠Example of usage :

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.

⁠How to use it with your own image

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;

⁠Debian

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

⁠Alpine

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

⁠GeoIP2 nginx module

https://github.com/leev/ngx_http_geoip2_module⁠

⁠Other nginx modules

Tag summary

Content type

Image

Digest

Size

51.4 MB

Last updated

about 6 years ago

docker pull anroe/nginx-geoip2