NGINX in docker
How to build a NGINX docker image with GeoIP2 module
There times that you may like to geo-locate incoming traffic, and execute some business logic accordingly. For example redirect users to a version of your website in their language. Up until not long ago the go-to solution was using ngx_http_geoip_module, however recently MaxMind has dropped the support for their now legacy database format, which effectively renders
ngx_http_geoip_module useless (at least for my use-case).
If you want to stick with NGINX as your web-server or reverse-proxy you still can use ngx_http_geoip2_module which supports the new database format. Instructions in the repository explain how to compile and configure it the module, and since this is not a tutorial I’m not going into it’s details.
The key is that you need to compile the module with exactly the same configuration as your NGINX, that is why you are better off compiling the two at the same time and avoid NGINX’s nagging about
Dynamic module is not binary compatible! Until a few months ago, the official NGINX Docker images would compile NGINX from the source, therefore it was easy to modify and incorporate new modules, but now that has changed and instead they pull down pre-build packages and install those.
I am no expert in any of this, but I spend a couple hours to adopt Dockerfiles from older versions and added
ngx_http_geoip2_module to NGINX image and updated NGINX to the latest mainline version. So if you just need an Alpine based NGINX image, you can find it here:
docker pull snjix/nginx:mainline-1.17.2-alpine
If you would like to take a look at the repo and adjust the Dockerfile to your needs, you can find it here!
Please note I only added