$sent_http_cache_control
$sent_http_cache_control contains the value of the 'Cache-Control' header sent in the HTTP response. — NGINX Core (HTTP)
Description
The $sent_http_cache_control variable retrieves the value of the 'Cache-Control' HTTP response header that NGINX sends to the client. It is set when NGINX processes a response, and it can be influenced by various configurations, such as `expires`, `add_header`, or `proxy_cache`. This variable is particularly useful when debugging or customizing the response headers returned by your server, allowing you to capture and log what caching directives are being sent out. Typically, the value of this variable could include directives like 'no-cache', 'private', 'max-age=3600', 'public', or could be empty if the header is not set. It can be used in combination with other variables to dynamically adjust response headers based on various server conditions or configurations, enhancing control over how responses are cached by clients and intermediaries in the HTTP chain. The variable is evaluated only after the response headers are sent out, meaning it reflects the final value that was included in the response. If there are multiple instances or manipulations of the Cache-Control header, this variable will hold the last value that was set before the response was completed.
Config Example
location /example {
proxy_pass http://backend;
add_header Cache-Control "private, max-age=3600";
log_format custom '$remote_addr - $remote_user [$time_local] "$request" $status $sent_http_cache_control';
access_log /var/log/nginx/access.log custom;
}Subsystem
httpCacheable
YesContexts
http, server, location, if, limit_exceptThe variable will be empty if the 'Cache-Control' header is not set in the response.
Ensure that you set the header in the right context; if set inside a location block, it will only apply to requests that fall within that context.
Changing response headers after they are sent will not affect this variable.