Overview
NGINX FastCGI caching significantly improves web performance by reducing Time to First Byte (TTFB). However, the open-source version of NGINX does not include built-in cache purging. The ngx_cache_purge module allows cache purging, but it requires compilation with NGINX.
Instead of recompiling NGINX on a production server, we will build the module separately on a development server and load it dynamically without downtime.
Step 1: Check Installed NGINX Version and Configuration
On the production server, run:
nginx -V
This command will output the installed NGINX version and configuration arguments, which look like this:
nginx version: nginx/1.24.0 (Ubuntu)
configure arguments: –prefix=/etc/nginx –modules-path=/usr/lib/nginx/modules –with-http_ssl_module –with-http_v2_module …
Copy these arguments as they are required for compiling the module later.
Step 2: Set Up a Development Server
Use a separate development server (e.g., a temporary cloud instance) to avoid installing unnecessary software on the production system.
Switch to the /tmp directory and download the NGINX source code matching the production version:
cd /tmp
wget http://nginx.org/download/nginx-1.24.0.tar.gz
Step 3: Download the NGX Cache Purge Module
Download the latest version of the cache purge module:
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
Extract the files:
tar -xzf nginx-1.24.0.tar.gz
tar -xzf ngx_cache_purge-2.3.tar.gz
Step 4: Install Dependencies for Compilation
Ensure required libraries are installed:
apt update && apt install -y build-essential libpcre3-dev libssl-dev zlib1g-dev libxml2-dev libxslt1-dev libgd-dev libgeoip-dev
Step 5: Add Cache Purge Module to NGINX
Navigate to the NGINX source directory:
cd nginx-1.24.0
Run the configure script with the same arguments from Step 1, plus the new cache purge module:
./configure –add-dynamic-module=../ngx_cache_purge-2.3 –with-cc-opt=’-g -O2 -fdebug-prefix-map=/build/nginx-1.24.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2′ –with-ld-opt=’-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC’ –prefix=/etc/nginx –modules-path=/usr/lib/nginx/modules –with-http_ssl_module –with-http_v2_module
Once configured, compile the module:
make modules
This will generate the ngx_http_cache_purge_module.so file in the objs directory.
Step 6: Enable Cache Purge Module on Production Server
Copy the compiled module to the production server:
scp objs/ngx_http_cache_purge_module.so user@your-production-server:/usr/lib/nginx/modules/
On the production server, load the module by adding the following line to /etc/nginx/nginx.conf:
load_module modules/ngx_http_cache_purge_module.so;
Alternatively, create a separate configuration file:
echo ‘load_module modules/ngx_http_cache_purge_module.so;’ | sudo tee /etc/nginx/modules-enabled/cache-purge.conf
Then, reload NGINX:
nginx -t && sudo systemctl reload nginx
Conclusion
We successfully added the NGX Cache Purge module to NGINX without reinstalling it or causing downtime. Now, you can purge cache dynamically using FastCGI.
For additional automation, consider integrating this with a reverse proxy like Varnish or configuring NGINX cache control headers.
Would you like help setting up an automated cache purge system?
Information reviewed and updated: August 28, 2026.
Published by: REVOLD BLOG – blog.revold.us
Powered by AIR RISE INC & REVOLD AI
Sponsored: CORPIUS
Author: Roman Kravchina
Related Reading on Revold Blog
- How to Install a Desktop Environment/GUI in Ubuntu Server
- How to Quickly Install Heimdall Using Docker
- How to set up an Ubuntu-based NAS
- How to install Cockpit for Linux
- More Developing & Programming guides
- How to Install Jitsi Meet on Ubuntu/Debian with Automatic Let’s Encrypt SSL
- How to Install Python Pip on Ubuntu 22.04
- This guide will show you how to install a desktop (GUI) graphical interface on your Ubuntu server.
- How to Install Searx Search Engine on Ubuntu / debianArch LinuxFedora / RHEL
- How to Install NVIDIA Drivers on Ubuntu 22.04 LTS
- How to Install Jellyfin Media Server on Ubuntu 24.04
- How to Install Virtualmin on Ubuntu 22.04 or 24.04
- How to Install UniFi Controller on Ubuntu 22.04 or 24.04
- Install Docker Compose on Linux Ubuntu 22.04, Debian or up
- How To Install Docker Compose on Ubuntu 22.04
- How to install and configure Grafana on CentOS 9 or 10 or 11′
- How to install Haproxy and Traefik on Proxmox VM with CentOS 9, 10, 11
- How to Install and Configure iRedMail on CentOS 9, 10, or 11


