Nginx use GIZP compression to improve the transmission speed of the website __nginx

Source: Internet
Author: User
Tags compressed file types

Css,js of the website, xml,html can use gzip compression when transmitting, improve the access speed,

The image on the website, video and other multimedia files, because the compression effect is not good, so for the picture does not need to support compression,

If you want to optimize, you can set the life cycle of the picture a bit longer, so that the client side to cache

In nginx.conf, the gzip configuration can be written in an HTTP segment, anywhere in the server section

Format is as follows


gzip on; Turn on the GZIP compression feature

Gzip_buffers 4k; or Gzip_buffers 8k; Here the table does not each compress 32 packs, each packet 4k size, sends to the client

Gzip_comp_level 6; This represents the compression level, can be 0 to 9 of any one, the higher the level, the smaller the compression, saving bandwidth resources, but also consumes CPU resources, so the general compromise of 6

Gzip_min_length 200; This means that if the file is less than 200 bytes, there is no compression, because it has no meaning, it is very small

Gzip_types text/css Text/xml Application/javascript; This indicates which types of files to compress, the text/html type is the default and does not need to write, if you do not know what type of file, you can find the file type in the Nginx directory,/var/mywww/nginx/conf/mime.types file records all can Compressed file types

Gzip_vary on; Can not write, indicating that I am transmitting data, to the client that I use GZIP compression


After the completion, save, exit, restart Nginx



As you can see, the file requested by the Web page is only 1.6K

and the actual file size is 4.5K (4500)









This diagram shows that the response header illustrates the use of gzip compression

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.