proxy_cache_purge

The `proxy_cache_purge` directive allows purging specific pages from the proxy cache in NGINX.

Syntaxproxy_cache_purge zone_name key;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The proxy_cache_purge directive is part of the NGINX Cache Purge module, which enables selective removal of cached content in a proxy caching environment. When a client makes a PURGE request with a specific key, this directive identifies which cached item should be removed, allowing for real-time updates when content changes on the backend. It can be configured to allow purging only for specific HTTP methods, and it can also restrict access based on client IP addresses.

To set up this directive, you can specify it in the http, server, or location context, and you must provide a cache zone and the corresponding cache key that you want to purge. The directive offers flexibility in configuration, including options to allow purging for all IPs, or restrict it to a list of specified clients. You can also specify the format of the response returned after a purge operation, which can include types such as HTML, JSON, or XML.

The proxy_cache_purge directive is critical for maintaining the freshness of content served through a proxy cache, making it an essential tool for dynamic web applications requiring real-time updates.

Config Example

location /purge {
    proxy_cache_purge my_cache $uri;
    allow 127.0.0.1;    # Allow localhost to purge
    deny all;           # Deny all other IPs
}

Ensure that the PURGE method is allowed and handled in your NGINX configuration, or these requests will be ignored.

Be cautious with allowing purging for all IP addresses, as it can lead to unauthorized users purging cache content. Especially in publicly accessible locations.

← Back to all directives