This is only for Official NGINX mainline Ubuntu releases
https://nginx.org/en/linux_packages.html#Ubuntu
- Install NGINX build dependencies
Redo after every NGINX upstream updates, in case of new build dependencies
apt build-dep nginx- Install additional build dependencies
libgeoip-devis forngx_http_geoip_module
libxml2-devandlibxslt1-devare forngx_http_xslt_module
apt install libgeoip-dev libxml2-dev libxslt1-dev- Alternatively, install
geoipandxsltdynamic modules if available from NGINX official repository
apt install nginx-module-geoip nginx-module-xslt- Download NGINX source
Let's use/usr/local/srcas our work directory
cd /usr/local/src
apt source nginx- Prepare directory for modules
mkdir nginx-VERSION/debian/modules
cd nginx-VERSION/debian/modules- Download
ngx_http_geoip2_module
wget https://github.com/leev/ngx_http_geoip2_module/archive/refs/heads/master.zip
unzip master.zip && rm master.zip-
Install
libmaxminddbforngx_http_geoip2_module
https://github.com/maxmind/libmaxminddb/blob/main/README.md#on-ubuntu-via-ppa -
Edit NGINX build flags
cd ../.. # /usr/local/src/nginx-VERSION
vi debian/rules-
Find
config.status.nginx: config.env.nginx -
Add the following at the end of the build flags (the line that starts with
CFLAGS="" ./configure) if not usinggeoipandxsltdynamic modules:
--add-module=$(CURDIR)/debian/modules/ngx_http_geoip2_module-master- Otherwise (this instead adds them straight into NGINX as static libraries):
--with-http_geoip_module --with-http_xslt_module --add-module=$(CURDIR)/debian/modules/ngx_http_geoip2_module-master- Build NGINX dep package
dpkg-buildpackage -uc -b- Install custom NGINX dep package
cd ..
dpkg --install nginx_???.deb- Prevent NGINX from being auto-updated with upstream package (once)
apt-mark hold nginx- Verify that your existing NGINX configs still work on the custom build, then restart NGINX service
nginx -t
systemctl restart nginx