Nginx the gzip configuration parameters in the server _nginx

Source: Internet
Author: User

Gzip (Gun-zip) is a compression technology, after gzip compressed page size can be turned into the original 30% or smaller.

Users browse the page when the speed will also be faster, gzip compressed pages need to serve the browser at the same time support, service-side compression reached

Browser to extract and parse, now most browsers have supported the resolution of gzip-enabled pages

Gzip Use Environment: http,server,location,if (x), generally I define it in the nginx.conf http{...} Between
gzip on;

Turn on gzip off
Gzip_min_length 1k;

Set the minimum byte to allow compression (obtained from the header's Content-length) recommendation is greater than 1k
gzip_buffers 4 16k;

Request Memory in 16k, 4 times times the size of the original data in 16k
Gzip_http_version 1.1;

Identify the version of the HTTP protocol, early browsers may not support gzip self-extracting, users will see garbled
Gzip_comp_level 2;

Level 1-9 the smallest compression is the fastest but consumes the CPU
gzip_types text/plain application/x-javascript text/css application/xml;

Matching compression type
gzip_vary on;

Enable the answer header "Vary:accept-encoding"

Gzip_proxied off;

Nginx is enabled when the reverse proxy, off (compression of data that turns off all proxy results), expired (enable compression, if the header includes "Expires" header information), No-cache (enable compression, header header contains " Cache-control:no-cache "), No-store (enable compression, header header contains" Cache-control:no-store "), private (enable compression, header header contains" Cache-control:private "), no_last_modefied (enable compression, header header does not contain" last-modified "), No_etag (enable compression, if header header does not include" ETag "header information) , auth (Enable compression if header header contains "Authorization" header information)
gzip_disable msie6;

(IE5.5 and IE6 SP1 use the MSIE6 parameter to prevent gzip compression) specify which browsers that do not need gzip compression (will match user-agents) and rely 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 to request memory space by a multiple of the block size
Param2:int (k) the rear unit is K
Example

Gzip_buffers 4 8k;

Gzip_comp_level
set the GZIP compression level, the lower the level of compression faster file compression than the smaller, whereas slower file compression than the larger
Param:1-9
Example

Gzip_com_level 1;

Gzip_min_length
when the return content is greater than this value, gzip is used for compression, in K, at 0 o'clock, all pages are compressed
Param:int
Example

Gzip_min_length 1000;

Gzip_types
sets the MIME type that needs to be compressed, and the non-set value is not compressed
Param:text/html|application/x-javascript|text/css|application/xml
Example

Gzip_types text/html;

For most text-oriented sites, the content of the text itself accounted for the vast majority of traffic. Although the volume of a single text is not large, the flow is considerable if there is a large number of them. After enabling gzip, you can drastically reduce the amount of traffic you need. The above code can be inserted into HTTP {...} In the configuration of the entire server, you can also insert into the virtual host's server {...} Or in the location module below.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.