Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › cache invalidation

How to Purge the NGINX Cache (and What “Hard Purge” Really Means)

By Freedom251 Team · · 4 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To purge an NGINX proxy-cache entry, send a request that matches its cache key to a location configured with proxy_cache_purge. A successful purge returns 204 No Content. That removes the entry from normal cache lookup, but a wildcard purge does not necessarily delete the corresponding files from disk immediately. NGINX documents this feature as part of a commercial subscription, so confirm it is available in your edition before configuring it.

How do I purge the NGINX cache?

NGINX’s documented approach is to map the HTTP PURGE method to a variable, then use that variable as the condition for proxy_cache_purge. A request using that method can then purge the matching proxy-cache entry. NGINX’s content-caching guide demonstrates this pattern:

As an Amazon Associate I earn from qualifying purchases.

map $request_method $purge_method {
    PURGE   1;
    default 0;
}

server {
    location / {
        proxy_pass http://backend;
        proxy_cache mycache;
        proxy_cache_purge $purge_method;
    }
}

With the configuration loaded, issue a purge request for the URL you want to invalidate:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -X PURGE https://example.com/path

The actual host, path, cache zone, and proxy configuration must match your setup. A successful operation returns 204 No Content; that confirms this NGINX cache accepted the purge, not that other independent caches or NGINX instances have also been invalidated.

Restrict who can purge

Do not expose an unrestricted purge endpoint to the public. Anyone able to purge entries can force cache misses and increase load on the origin. NGINX’s guide shows using geo and map to permit selected IP addresses. Apply an equivalent access control appropriate to your deployment, and ensure the purge request is routed through the protected configuration.

How do I clear one cached URL?

A purge selects an entry by its cache key, not by an abstract idea of a page. The default proxy cache key is based on the scheme, proxy host, URI, and arguments; a custom proxy_cache_key changes the inputs. See the NGINX proxy module reference.

Consequently, the purge request must produce the same effective key as the request that populated the cache. If the key includes query arguments, host information, cookies, or other configured values, purging only a familiar-looking path may select a different entry. Check the effective cache-key configuration before assuming a URL identifies exactly one cached response.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I clear the whole cache?

NGINX documents wildcard purge keys: a key ending in * can match multiple entries. Wildcard matching is still based on the configured cache key, so determine which key prefix you intend to match before using it. A broad match can affect more cached responses than a single-URL purge.

There is an important distinction between invalidation and physical file removal. Wildcard-matched entries can stop being served from the active cache while their files remain on disk. Those files may be removed through inactivity cleanup, by the cache purger, or when a client later attempts to access an entry. To have a background process remove wildcard-matched files, NGINX documents enabling purger=on in the relevant proxy_cache_path configuration. The module reference also documents the cache-purger parameters, including purger_files, purger_threshold, and purger_sleep.

Thus, “hard purge” should not be taken to mean that every matching cache file is synchronously erased from storage as soon as the purge request completes. If immediate physical deletion is a requirement, verify the behavior of your specific deployment rather than relying on wildcard purge alone.

Why is the old response still being served after I purged it?

  • The purge key did not match. Compare the configured proxy_cache_key with the request used to purge, including host, scheme, URI, and query arguments where applicable.
  • You purged one cache layer, not all of them. A 204 confirms success at the NGINX cache that handled the request; it does not establish that a separate NGINX instance, CDN, browser, or other cache has been cleared.
  • You expected wildcard disk cleanup to be immediate. A wildcard purge can leave files on disk for later cleanup even though they are no longer active cache hits.
  • The requested location is not using the expected cache configuration. Confirm that the request reaches the server and location configured with the intended cache zone and purge condition.

If explicit purging is unavailable or unsuitable, NGINX also documents expiry and revalidation directives for controlling freshness. Those mechanisms determine when cached content expires or is checked again; they are not the same as explicitly purging a selected entry.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Is purge available in every NGINX build?

No. The NGINX proxy module reference classifies proxy_cache_purge as part of a commercial subscription. Confirm the feature’s availability and packaging for the NGINX edition and deployment you use; the cited documentation does not establish current plan names, pricing, or terms.

Other options exist, but check compatibility rather than assuming they work with every release. FRiCKLE’s ngx_cache_purge project describes support for proxy, FastCGI, SCGI, and uWSGI caches; its current maintenance and compatibility with a particular NGINX version are not established here. GetPageSpeed describes a cache purge and tag invalidation module and says it requires its Pro plan or higher. These are vendor or third-party options, not interchangeable guarantees of support for every cache type or topology.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

cache invalidationNGINXproxy cacheweb servers

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.