unbrotli

The `unbrotli` directive enables decompression of Brotli-encoded responses for clients that do not support Brotli.

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

Description

The unbrotli directive is part of the NGINX module ngx_unbrotli, which is designed to handle Brotli-compressed responses (indicated by the 'Content-Encoding: br' header). When this directive is enabled, NGINX inspects the Accept-Encoding header from the client's request to determine their compression capabilities. If a client does not support Brotli compression, the server decompresses the Brotli-encoded content before sending it to the client, ensuring compatibility and providing a seamless experience regardless of the client's capabilities.

The directive can be specified in the http, server, or location contexts and operates with a simple flag (on or off). By default, it is set to off, meaning that Brotli responses will not be decompressed unless explicitly enabled. Additionally, users can utilize the unbrotli_force directive, which enforces decompression for all Brotli responses regardless of the client's stated preferences. Alongside this, the unbrotli_buffers directive allows configuration of the number and size of memory buffers allocated for the decompression process, which can be adjusted to optimize performance for large responses, but may increase memory usage.

Overall, the unbrotli directive plays a critical role in ensuring users with legacy or non-Brotli-supporting clients receive the content they need, while simultaneously allowing server operators to take advantage of Brotli's efficient compression for storage and bandwidth savings.

Config Example

location /assets/ {
    unbrotli on;
    unbrotli_buffers 32 4k;
    ...
}

Forgetting to enable unbrotli when Brotli responses are used can lead to issues for clients that do not support Brotli.

Misconfiguring buffer sizes can result in memory overhead or loss of performance during decompression.

Ignoring the effect of unbrotli_force can lead to unexpected behavior, where all clients receive decompressed responses regardless of their capabilities.

← Back to all directives