Skip to content

Instantly share code, notes, and snippets.

@BobbyWibowo
Last active August 19, 2022 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BobbyWibowo/b0296d8a9c52f36c3ed53a16546ae8d7 to your computer and use it in GitHub Desktop.
Save BobbyWibowo/b0296d8a9c52f36c3ed53a16546ae8d7 to your computer and use it in GitHub Desktop.

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-dev is for ngx_http_geoip_module
    libxml2-dev and libxslt1-dev are for ngx_http_xslt_module
apt install libgeoip-dev libxml2-dev libxslt1-dev
  • Alternatively, install geoip and xslt dynamic modules if available from NGINX official repository
apt install nginx-module-geoip nginx-module-xslt
  • Download NGINX source
    Let's use /usr/local/src as 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
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 using geoip and xslt dynamic 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment