Skip to content

Instantly share code, notes, and snippets.

Last active August 19, 2022 00:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?

This is only for Official NGINX mainline Ubuntu releases

  • 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
unzip && rm
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:

  • 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