srcache_ignore_content_encoding

The `srcache_ignore_content_encoding` directive controls whether NGINX should ignore Content-Encoding headers when fetching cached responses.

Syntaxsrcache_ignore_content_encoding on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The srcache_ignore_content_encoding directive is a flag used in the context of HTTP, server, and location blocks. When set to 'on', NGINX will ignore any Content-Encoding headers present in the responses it fetches from the upstream servers, allowing the resource to be served in its unencoded form from the cache. This is particularly useful in scenarios where clients may not handle encodings correctly or when different clients expect different response formats.

Under normal circumstances, if the upstream server responds with different encodings (like gzip, deflate, etc.), NGINX might cache the responses with those encodings. When the srcache_ignore_content_encoding directive is enabled, the cached content will always be stored and served without any encoding, regardless of what the upstream server sends. Thus, it can simplify handling responses in a uniform manner, particularly in setups with multiple clients or microservices that may interact with the same cached content but require it to be unaltered.

When this directive is set, the actual fetched content from upstream is transformed into a raw response, discarding any indication of its original encoding. This means that when configured properly, it helps ensure consistent behavior across various client requests while optimizing resource utilization in NGINX's caching mechanism.

Config Example

location /example {
    srcache_fetch my_cache;
    srcache_ignore_content_encoding on;
}

Ensure that all clients can handle unencoded content since this will not serve gzipped or encoded responses.

Remember that enabling this may increase the response size since compressed content will be served uncompressed.

← Back to all directives