An explanation of the GZIP compression function of the open Nginx

Source: Internet
Author: User

By default, Nginx gzip compression is off, gzip compression function is to allow you to save a lot of bandwidth, but will increase the cost of the server CPU Oh, nginx by default only text/html compression, if you want to compress the content outside the HTML, We need to adjust it manually.

The instructions for opening gzip are as follows:

The code is as follows Copy Code

gzip on;
Gzip_http_version 1.0;
Gzip_disable "MSIE [1-6].";
Gzip_types text/plain application/x-javascript text/css text/javascript;

For Gzip_types, if you want the image to also turn on gzip compression, use the following paragraph:

Gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif Image/png;

Web site gzip compression, not only to save bandwidth, but also to quickly respond to user access, in Nginx, the method of opening gzip compression:
gzip on; (Enable gzip compression feature)

Gzip_proxied any; (this option is enabled when Nginx is a front-end agent, which means that compression is enabled unconditionally regardless of what information is returned by the backend server's headers header)

Gzip_min_length 1024; (The smallest compressed page, if the page is too small, it may be more pressure, there are more than 1K page to enable compression)

Gzip_buffers 4 8k; (Set the system to get a cache of several units for storing gzip compressed result data streams)

Gzip_comp_level 3; (Compression level, 1 compression than the minimum processing speed, 9 compression than the maximum but the slowest processing, but also the most CPU, the general set to 3 on it)

Gzip_types text/plain text/css application/x-javascript application/javascript application/xml; (What type of page or document is enabled for compression)


Attention:

1. Where the gzip_http_version is set, its default value is 1.1, which means that the request to the http/1.1 protocol is gzip compressed
If we use Proxy_pass for a reverse proxy, then the upstream server between the Nginx and the backend is communicated with the http/1.0 protocol.
This module makes it possible the transfer requests to another server.
It is a http/1.0 proxy without the ability for keep-alive requests yet. (as a result, backend connections is created and destroyed on every request.) Nginx talks http/1.1 to the browser and http/1.0 to the backend server. As such it handles keep-alive to the browser.
If we use Nginx to do the cache Server through the reverse proxy, and the front-end Nginx does not open gzip
At the same time, our backend nginx is not set Gzip_http_version to 1.0, then the cache URL will not be gzip compressed

2. Gzip_disable is set to disable IE6 gzip compression, again because of the IE6 of the Cup
IE6 Some versions of GZIP compression support is not good, will cause the page suspended animation, today's students tested the problem
Later debugging, found that the IMG was gzip after the death of IE6, the gzip compression of IMG removed after the normal
To ensure that other IE6 versions are not problematic, the gzip_disable settings are added.

An explanation of the GZIP compression function of the open Nginx

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.