proxy_no_cache

The `proxy_no_cache` directive inhibits caching for specified requests in NGINX's proxy module.

Syntaxproxy_no_cache condition | = | 0 | 1;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The proxy_no_cache directive is utilized within the proxy module of NGINX to control caching behavior on upstream responses. By using this directive, you can specify conditions that will determine whether a response is eligible for caching or not. The directives allow for boolean expressions that evaluate to true or false, enabling flexibility in managing cache storage based on various request parameters such as headers, cookies, and variables. When the specified condition evaluates as true, NGINX will not cache the response, effectively bypassing cache storage.

This directive supports one or more arguments, allowing administrators to tailor caching logic precisely according to their application’s needs. In practice, you might want to prevent caching for authenticated users or specific request types; for instance, if the request contains a certain cookie value or if a header is present. The result is an effective mechanism to ensure that sensitive or user-specific data is served fresh from the backend server without being cached.

Config Example

location /api {
    proxy_pass http://backend;
    proxy_no_cache $http_cache_control;
}

Ensure that the conditions passed to proxy_no_cache are correctly configured; otherwise, caching behavior may not work as intended.

Using complex boolean expressions may make debugging cache issues challenging.

This directive does not apply when the response already has caching headers set; ensure proper response header management.

← Back to all directives