proxy_cache_bypass
The `proxy_cache_bypass` directive controls whether specific requests bypass the proxy cache in NGINX. — NGINX HTTP Core
Описание
The `proxy_cache_bypass` directive is used within the HTTP, server, or location contexts to define conditions under which a request should bypass the proxy cache. It accepts one or more arguments, which can be variables, nginx built-in variables, or any other valid identifiers that evaluate to a truthy value when determining if a request should skip the cache. When a matching condition is satisfied, NGINX will serve the request directly from the origin server instead of returning the cached version, effectively allowing dynamic responses for specific requests while still utilizing caching for others. This directive is particularly useful when certain requests should not be cached, such as requests containing sensitive user-specific data or dynamic content that changes frequently. For example, you could set it to bypass caching when certain cookies or request headers are present. This allows fine-grained control over cache behavior and optimizes the performance by ensuring that only appropriate content is served from the cache, while still allowing the rest of the data to be cached and served efficiently.
Пример конфига
location / {
proxy_pass http://backend;
proxy_cache my_cache;
proxy_cache_bypass $cookie_nocache;
}Ensure that the specified variable or expression evaluates correctly to avoid unintended caching behavior.
Overly broad conditions can lead to excessive cache misses, impacting performance and server load.