Nginx Configure gzip Compression page _nginx

Source: Internet
Author: User

Gzip (Gnu-zip) is a compression technique. After gzip compressed page size can be changed to the original 30% or even smaller, so that users browse the page when the speed will be much more. Gzip compressed page need both browser and server support, is actually server-side compression, upload browser after the browser decompression and resolution.

The Nginx compression output has a set of gzip compression instructions to implement. The instructions are located between two curly braces in http{.

gzip on;
This directive is used to turn the Gzip module on or off (On/off)

Gzip_min_length 1k;
Sets the minimum number of bytes of pages allowed to compress, and the number of page bytes is obtained from the header content-length. The default value is 0, regardless of how much of the page is compressed. It is recommended that you set the number of bytes larger than 1k, less than 1k may be more pressing.

Gzip_buffers 4 16k;
Set up the system to get several units of cache to store the gzip compressed result data stream. 4 16k represents 16k as the installation of the original data size in 16k of 4 times times the application memory.

Gzip_http_version 1.1;
Protocol version to identify HTTP (1.0/1.1)

Gzip_comp_level 2;
gzip compression ratio, 1 compression faster than the minimum processing speed, 9 compression than the largest but the slowest processing speed (faster transmission but more CPU consumption)

Gzip_types text/plain application/x-javascript text/css application/xml

Matches the MIME type for compression, and the "text/html" type is always compressed, regardless of whether it is specified.

Gzip_vary on;
and HTTP headers have a relationship, add a vary head, to the proxy server, and some browsers support compression, some do not support, so avoid wasting unsupported also compression, so according to the client's HTTP headers to determine whether the need for compression.

Also, because IE6 does not support GIZP decompression, the gzip compression feature is turned off under IE6. Use

Copy Code code as follows:

Gzip_disable "MSIE [1-6]\.";

The Nginx Configuration gzip section is as follows:

Copy Code code as follows:

gzip on;
Gzip_min_length 1k;
Gzip_buffers 64k;
Gzip_http_version 1.1;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
Gzip_disable "MSIE [1-6]\.";

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.