Nginx gzip compression Configuration

Source: Internet
Author: User

With the development of nginx, more and more websites are using nginx, so the optimization of nginx becomes more and more important. Today, let's take a look at how gzip compression of nginx is compressed?

Gzip (GNU-zip) is a compression technology. After gzip compression, the page size can be changed to 30% or even smaller. In this way, the speed of browsing the page is much faster. Gzip compression pages must be supported by both the browser and the server. In fact, they are compressed by the server. After being uploaded to the browser, the browser decompress and parse them. We don't need to worry about browsers, because most browsers currently support parsing gzip pages.
The nginx compression output is implemented by a set of gzip compression commands. The related commands are located at http {....} Between Two braces.

Gzip on;
// This command is used to enable or disable the gzip module (ON/OFF)

Gzip_min_length 1 K;
// Sets the minimum number of page bytes that can be compressed. The number of page bytes is obtained from the Content-Length header of the header. The default value is 0, and most pages are compressed. We recommend that you set the size to 1 kb. smaller than 1 kb may increase the pressure.

Gzip_buffers 4 16 K;
// Set the system to obtain several units of cache for storing gzip compressed result data streams. 4 16 k indicates that the size of the original data is 4 times the size of the requested memory in 16 K.

Gzip_http_version 1.1;
// Identify the HTTP protocol version (1.0/1.1)

Gzip_comp_level 2;
// Gzip compression ratio. The minimum compression ratio is the fastest, and the maximum compression ratio is 9, but the processing speed is the slowest (fast transmission but CPU consumption)

Gzip_types text/plain application/X-JavaScript text/CSS application/XML
// Match the MIME type for compression. Whether specified or not, the "text/html" type is always compressed.
Gzip_vary on;
// It is related to the HTTP header and adds a vary header for the proxy server. Some browsers support compression and some do not support compression, so avoid wasting and compressing unsupported ones, therefore, we can determine whether compression is required based on the HTTP header of the client.

The gzip section for nginx configuration is as follows:
Gzip on;
Gzip_min_length 1 K;
Gzip_buffers 16 64 K;
Gzip_http_version 1.1;
Gzip_comp_level 6;
Gzip_types text/plain application/X-JavaScript text/CSS application/XML;
Gzip_vary on;

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.