Detailed explanation and configuration of gzip module of nginx
1. The function of gzip module
The gzip module must be opened in both test and production environments. This module can efficiently compress the content of the page, whether html or css, js or pictures, saving bandwidth resources, improving the loading speed of the website and bringing better service to visitors.
2. Enable gzip
Just configure it in nginx's configuration file nginx.conf.
In http {
Gzip on
Gzip_min_length 1k
Gzip_buffers 4 32k
Gzip_http_version 1.1
Gzip_comp_level 6
Gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml
Gzip_vary on
} module to add
3. Detailed explanation
Gzip on; enables compression. Default is off.
Gzip_min_length 1k; set the compression threshold. When set to 1k, it means that if the file to be compressed is less than 1k, it will be compressed.
Gzip_buffers 432k; sets the number and size of compressed buffers. 432k means to apply for four buffers with a size of 32k.
Gzip_http_version 1.1 identifies the version of the http protocol
Gzip_types text/plain text/css text/javascript
The application/javascript application/xml; gzip_types option is very important, which specifies the types of files that can be compressed. If a certain type of file is not compressed and does not work in practice, find the reason here.
Gzip_vary on; enables the response header "Vary: Accept-Encoding"
Gzip_comp_level 6; compression ratio, used to specify GZIP compression ratio, 1 compression ratio is the smallest, processing speed is the fastest, 9 compression ratio is the largest, the transmission speed is fast, but the processing is slow, and it consumes CPU resources.
Enabled when gzip_proxied off; nginx is a reverse proxy
Gzip_disable msie6; makes IE6 not applicable gzip,IE6 support for gzip is not good, you may see garbled.