Nginx gzip compression boosts website speed

Source: Internet
Author: User

One: Nginx gzip compression boost website speed

We're looking at News.163.com's head information.

Request:

Accept-encoding:gzip,deflate,sdch

Response:

Content-encoding:gzip

content-length:36093

Then save the page, observe, about 10W bytes, the actual transmission of 36093 bytes

The reason-------is gzip compression.

Principle:

Browser---Request----> claims can accept gzip compression or deflate compression or compress or SDCH compression

From the point of view of the HTTP protocol-the request header declaration Acceopt-encoding:gzip deflate SDCH (refers to the compression algorithm, which SDCH is a compression method advocated by Google, currently support a few servers)

Server-to-response---compress content in gzip----> Send to Browser

Browse <-----decode gzip-----Receive gzip compressed content----

Calculate the bandwidth savings:

Suppose news.163.com PV 200 million

2*10^8 * 9*10^4 bytes = =

2*10^8 * 9 * 10^4 * 10^-9 = 12*k*g = 18T

The bandwidth savings are very alarming.

Common parameters for gzip configuration

Gzip On|off; #是否开启gzip

Gzip_buffers 4k| 8K #缓冲 (compression buffers a few blocks in memory? How big is each chunk?)

Gzip_comp_level [1-9] #推荐6 compression level (the higher the level, the smaller the pressure, the more wasted CPU computing resources)

Gzip_disable #正则匹配UA What kind of Uri does not perform gzip

Gzip_min_length 200 # Start compressing the minimum length (no more small, no compression, meaning not)

Gzip_http_version 1.0|1.1 # Start Compressed HTTP protocol version (can not be set, currently almost all 1.1 protocol)

Gzip_proxied # Set the requestor proxy server, how to cache the content

Gzip_types Text/plain Application/xml # for which types of files are compressed such as txt,xml,html, CSS

Gzip_vary On|off # Whether to transmit GZIP compression flag

------Compressed gzip Configuration--------------

Configuring in Server Fault

server{

gzip on;

Gzip_buffers 4k;

Gzip_comp_level 6;

Gzip_min_length 200;

Gizp_type text/css Text/xml Applocation/x-javascript;

}

---------------------------

Attention:

Picture/mp3 Such a binary file that does not have to be compressed

Because the compression ratio is smaller, such as 100->80 bytes, and compression is CPU-intensive.

Smaller files do not have to be compressed,

Nginx gzip compression boosts website speed

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.