Details of the GZip configuration parameters in the Nginx server

  • 2020-05-14 05:32:29
  • OfStack

gzip(GUN-ZIP) is a compression technique that can reduce the page size to 30% or less after gzip compression.

When users browse the page, the speed will also be faster. The compressed page of gzip needs to be supported by the server side at the same time

The browser unzips and parses, and most browsers now support parsing gzip pages

gzip use environment: http, server location, if (x), 1, I define it in nginx conf http {... . } between
gzip on;

Turn gzip off off
gzip_min_length 1k;

Setting the minimum number of page bytes allowed for compression (from Content-Length in the header header) is recommended to be greater than 1k
gzip_buffers 4 16k;

Request memory in units of 16k, 4 times the original data size in units of 16k
gzip_http_version 1.1;

Identify the version of the http protocol, early browser may not support gzip self-decompression, users will see the garbled code
gzip_comp_level 2;

Grades 1-9 minimum compression is fastest but consumes cpu
gzip_types text/plain application/x-javascript text/css application/xml;

Matching compression type
gzip_vary on;

Enable the reply header "Vary: Accept-Encoding"

gzip_proxied off;

nginx is enabled as a reverse agent,off(turns off the compression of all agent results),expired(turns off compression if header header contains "Expires" header), no-cache (turns on compression,header header contains "Cache-Control: no-cache "), no-store (turns on compression,header header contains" Cache-no-store "),ES88 EN(with compression enabled,header header contains "Cache-Control :private"),no_last_modefied(with compression enabled,header header does not contain" Last-Modified "),no_etag(with compression enabled, header header does not contain "Etag" header),auth(with compression enabled, header header contains "Authorization" header),auth(with compression enabled, header header contains "Authorization" header)
gzip_disable msie6;

(IE5.5 and IE6 SP1 use the msie6 parameter to disable gzip compression) to specify which browsers do not need gzip compression (which will match User-Agents), depending on the PCRE library

gzip
Decide whether to open the gzip module
example:


gzip on;

gzip_buffers
Set the size of the gzip request memory, which is used to request memory space in multiples of the block size
param2:int(k) followed by k
example:


gzip_buffers 4 8k;

gzip_comp_level
Set gzip compression level, the lower the level, the faster the compression speed, the smaller the file compression ratio, and the slower the speed, the larger the file compression ratio
param:1-9
example:


gzip_com_level 1;

gzip_min_length
When the returned content is greater than this value, gzip is used for compression. When K is used as a unit, all pages are compressed when the value is 0
param:int
example:


gzip_min_length 1000;

gzip_types
Set the MIME type to be compressed. Unset values are not compressed
param:text/html|application/x-javascript|text/css|application/xml
example:


gzip_types text/html;

For most text-based sites, the content of the text itself accounts for the vast majority of the traffic. Although the volume of a single text is not large, the traffic is considerable if the volume is large. With GZIP enabled, you can drastically reduce the amount of traffic you need. The above code can be inserted into http {... } the entire server configuration, can also be inserted into the virtual host server {... } or the location module below.


Related articles: