gzip_min_length

Sets the minimum length of response body for Gzip compression.

Syntaxgzip_min_length size;
Default20
Contexthttp, server, location
Arguments1

Description

The gzip_min_length directive controls the minimum size of the response body before it is eligible for Gzip compression in NGINX. When a response is generated, if the body size is smaller than the specified length, it will not be compressed. This is useful for optimizing performance, as compressing small responses can be more CPU-intensive than simply sending them uncompressed.

The directive accepts an argument that defines the minimum length in bytes, and can be set in the http, server, or location contexts. This allows different configurations for different levels of the server hierarchy. By adjusting this value, administrators can find a balance between compression overhead and network bandwidth savings. It is particularly important in scenarios where responses consist of small resources (like images or scripts) that may not benefit significantly from Gzip compression.

To set this directive, you simply provide a numeric value representing the byte length that will serve as the threshold. For example, setting gzip_min_length 1000; means that any response body smaller than 1000 bytes will be sent uncompressed, while larger bodies will undergo compression. This behavior helps in mitigating the performance lag caused by handling many small compressed files.

Config Example

http {
    gzip on;
    gzip_min_length 1000;
}

Setting a value too high might lead to increased bandwidth usage for small responses.

If there are multiple configurations, the effective value may vary depending on the context in which it is set.

← Back to all directives