gzip_comp_level
The gzip_comp_level directive sets the compression level for gzip content encoding in NGINX.
Description
The gzip_comp_level directive within the NGINX HTTP Core module allows administrators to specify the level of compression applied when serving gzip-encoded content. Valid values range from 1 to 9, where 1 signifies the least amount of compression (and fastest processing speed) and 9 indicates the highest level of compression (which is more CPU-intensive).
By default, gzip_comp_level is set to 1, meaning that content will be lightly compressed. Increasing this value improves the compression ratio, which can save more bandwidth; however, it also results in increased CPU usage during the compression process. This trade-off must be carefully considered, particularly for sites with high traffic, where excessive CPU load can impact performance. Additionally, the compression level applies only to the data that is eligible for gzip compression, such as HTML, CSS, and JavaScript files, as specified by other gzip directives.
This directive is context-sensitive and may be defined within the http, server, or location contexts, allowing for flexible configuration based on specific needs. Setting it in the http context will apply the specified compression level globally, while settings in the server or location contexts can override the global setting for more granular control.
Config Example
http {
gzip on;
gzip_comp_level 5;
}Setting the level too high can lead to increased CPU usage, potentially affecting the performance of the server.
Not all file types are eligible for gzip compression; ensure that the appropriate settings for content types are configured as well.