compression_normalize_accept_encoding
The `compression_normalize_accept_encoding` directive configures NGINX to normalize the Accept-Encoding header from client requests for consistent compression handling.
Description
The compression_normalize_accept_encoding directive is part of the NGINX Accept-Encoding Normalization module, which is designed to effectively manage and standardize the Accept-Encoding headers sent by clients. By specifying combinations of supported compression methods, this directive allows the server to determine which encoding type to prioritize when generating responses. This is particularly useful for optimizing compression efficiency and achieving better cache performance.
When the directive is used, it accepts a list of one or more compression combinations. For example, using a configuration like compression_normalize_accept_encoding gzip,br,zstd gzip,br zstd br gzip; instructs NGINX to first try to respond with gzip and Brotli (br) and then fall back to zstd if the preferred combinations are not matched within the client’s Accept-Encoding header. If none of the specified combinations are found within the incoming request, the directive will direct NGINX to delete the Accept-Encoding header entirely. This stringent normalization process thus prevents issues that could stem from inconsistent Accept-Encoding values.
Additionally, there is a variable $compression_original_accept_encoding that retains the original Accept-Encoding header value before normalization. This can be leveraged for debugging or logging purposes, ensuring that the server maintains awareness of the initial client request settings despite normalization taking place.
Config Example
http {
compression_normalize_accept_encoding gzip,br,zstd gzip,br zstd br gzip;
server {
listen 80;
server_name example.com;
location / {
# Your configurations
}
}
}Ensure that the combinations specified in the directive are valid and supported by the server's compression modules.
Accurate ordering of the combinations is crucial, as the first match found will dictate the final Accept-Encoding header.
Be cautious about the use of 'off'; if set incorrectly, it can undermine the benefits of compression normalization.