sequence

Nginx ngx_HTTP_gzip_module ngx_HTTP_gzip_STATIC_module ngx_HTTP_gzip_STATIC_module

gzip

The name of the The default configuration scope The official instructions Chinese reading The module
gzip gzip off; http, server, location, if in location Enables or disables gzipping of responses. Sets whether to enable gzip compression of the back-end response, and then returns the compressed content to the front-end ngx_http_gzip_module
gzip_buffers Gzip_buffers 32 4k or 16 8K; http, server, location Sets the number and size of buffers used to compress a response. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform. Set the number of buffers used to compress the back-end response and the size of each buffer. The default size of each buffer is one memory page, which may be 4K or 8K depending on the platform ngx_http_gzip_module
gzip_comp_level gzip_comp_level 1; http, server, location Sets a gzip compression level of a response. Acceptable values are in the range from 1 to 9. Specifies the level of gzip compression. The default value is 1. The value ranges from 1 to 9, where 1 is minimum compression (fast) and 9 is maximum compression (slow) ngx_http_gzip_module
gzip_disable No default value http, server, location Disables gzipping of responses for requests with User-Agent header fields matching any of the specified regular expressions. The re matches the value in the User-agent. If it matches, gZIP is not performed ngx_http_gzip_module
gzip_min_length gzip_min_length 20; http, server, location Sets the minimum length of a response that will be gzipped. The length is determined only from the Content-Length response header field. Set the threshold for gzip compression. If the content-Length of the back-end response is smaller than the threshold, gzip compression is not performed ngx_http_gzip_module
gzip_http_version Gzip_http_version 1.1; http, server, location Sets the minimum HTTP version of a request required to compress a response. Set the minimum HTTP version for gzip compression ngx_http_gzip_module
gzip_proxied gzip_proxied off; http, server, location Enables or disables gzipping of responses for proxied requests depending on the request and response. The fact that the request is proxied is determined by the presence of the “Via” request header field. Gzip is determined based on the value of the associated header of the request or response ngx_http_gzip_module
gzip_types gzip_types text/html; http, server, location Enables gzipping of responses for the specified MIME types in addition to “text/html”. The special value “*” matches any MIME Type (0.8.29). Responses with the “text/ HTML “type are always compressed. Specifies which MIME types enable gzip compression, default text/ HTML ngx_http_gzip_module
gzip_vary gzip_vary off; http, server, location Enables or disables inserting the “Vary: Accept-Encoding” response header field if the directives gzip, gzip_static, or gunzip are active. Whether to say Vary: accept-encoding to response header ngx_http_gzip_module
gzip_static gzip_static off; http, server, location Enables (“on”) or disables (“off”) checking the existence of precompressed files. The following directives are also taken into account: gzip_http_version, gzip_proxied, gzip_disable, and gzip_vary. When enabled, requests are sent to the file system with the “.gz” extension in the same URL path. If it exists, send it directly. If it doesn’t, gzip it and send it again ngx_http_gzip_static_module

The instance

http {
    gzip on;
    gzip_buffers 8 16k; ## This limits nginx's ability to compress files larger than 128K
	gzip_comp_level 2;
    gzip_disable "MSIE [1-6]\.(? ! .*SV1)";
    gzip_min_length 512; # # unit of byteGzip_http_version 1.0; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; gzip_static on; / /... }Copy the code

doc

  • nngx_http_gzip_module
  • Accelerated Nginx: Enable gzip and caching
  • mozilla Vary
  • Some research on Vary in THE HTTP protocol
  • Use of the gzip_static module in Nginx