Cache Purge

Flush the exact cache entry you want. Not the whole cache.

$ sudo apt install nginx-module-cache-purge
Package
nginx-module-cache-purge
Section
Caching
Replaces
libnginx-mod-http-cache-purge
Upstream
github.com/FRiCKLE/ngx_cache_purge ↗
Distros
Debian 12, 13 · Ubuntu 22.04, 24.04, 26.04
Arch
amd64, arm64

What it does

nginx's built-in caching gives you two options: wait for TTL, or nuke everything. Cache Purge adds a third: just remove the one entry you want gone. Hit a purge endpoint and nginx drops the matching cache entry immediately, nothing else touched. Works with proxy_cache (reverse proxy) and fastcgi_cache (PHP-FPM). The usual pattern is a restricted purge endpoint your CMS, deploy pipeline, or CDN webhook calls on content change. Cache entries are matched by cache key, which typically maps directly to URL. Long TTLs with instant on-demand invalidation. That's the setup most caching configs actually want.

When to use it

  • Instantly invalidate CMS content on publish without flushing unrelated cache
  • Integrate with deployment pipelines to purge affected URLs on release
  • Use long TTLs with selective purge instead of short TTLs as a workaround
  • Cache invalidation APIs for headless CMS and Jamstack setups
  • Purge fastcgi_cache entries from PHP application hooks

Configuration

A starting point. Adjust to taste.

nginx.conf
proxy_cache_path /var/cache/nginx
                 levels=1:2
                 keys_zone=main_cache:10m
                 max_size=1g;

server {
  location / {
    proxy_cache       main_cache;
    proxy_cache_valid 200 7d;
    proxy_pass        http://backend;
  }

  # Purge endpoint (restrict by IP in production)
  location ~ /purge(/.*) {
    allow  127.0.0.1;
    deny   all;
    proxy_cache_purge main_cache "$scheme$request_method$host$1";
  }
}

Install from scratch

You'll need nginx from nginx.org configured first. These packages won't load on the distro nginx. Then add the Blendbyte repository if you haven't already:

Add repository and install
sudo install -d -m 0755 /etc/apt/keyrings

curl -fsSL https://apt.blendbyte.net/nginx/blendbyte-archive-keyring.gpg \
  | sudo tee /etc/apt/keyrings/blendbyte.gpg >/dev/null

echo "deb [signed-by=/etc/apt/keyrings/blendbyte.gpg] https://apt.blendbyte.net/nginx $(lsb_release -cs) main" \
  | sudo tee /etc/apt/sources.list.d/blendbyte.list

sudo apt update
sudo apt install nginx-module-cache-purge

Most modules auto-enable on install. If yours didn't:

Enable manually (if needed)
$ sudo ln -s /etc/nginx/modules-available/50-mod-cache-purge.conf \
  /etc/nginx/modules-enabled/
$ sudo nginx -t && sudo systemctl reload nginx

Replacing a Sury package?

This replaces libnginx-mod-http-cache-purge from the old Sury nginx repository. The package declares Replaces and Conflicts, so once your apt sources point at nginx.org and Blendbyte, a regular apt upgrade swaps it in. No manual cleanup.

Switching sources also moves you from Sury's nginx binary to nginx.org's. The migration guide walks through it in one go.

Upstream project

We package this from the upstream open-source project. If it's a bug in the module itself (not in our packaging), report it upstream at github.com/FRiCKLE/ngx_cache_purge ↗