Nginx gzip Configuration Parameters detailed _nginx

Source: Internet
Author: User
Tags auth

Nginx has gzip module http://wiki.nginx.org/NginxChsHttpGzipModule, this module supports the online real-time compression of output data streams. After good configuration optimization, can greatly improve the efficiency of the site's output.

__ Use Example __

Copy Code code as follows:

gzip on;
Gzip_min_length 1000;
Gzip_proxied expired No-cache No-store private auth;
Gzip_types Text/plain Application/xml;

Built-in variable $gzip _ratio can get to the gzip compression ratio

Instructions:

Copy Code code as follows:

[#gzip gzip]
[#gzip_buffers Gzip_buffers]
[#gzip_comp_level Gzip_comp_level]
[#gzip_min_length Gzip_min_length]
[#gzip_http_version Gzip_http_version]
[#gzip_proxied gzip_proxied]
[#gzip_types Gzip_types]

Gzip

Syntax: gzip On|off
Default value: gzip off
Scopes: HTTP, server, location, if (x) location
Turn on or off the gzip module

Gzip_buffers

Syntax: gzip_buffers number Size
Default value: Gzip_buffers 4 4k/8k
Scopes: HTTP, server, location
Set up the system to get several units of cache to store the gzip compressed result data stream. For example, 4 4k represents 4k, and applies memory at 4 times times the size of the original data in 4k. 4 8k represents 8k as the original data size in 8k of 4 times times the application of memory.

If not set, the default value is to request the same amount of memory space as the original data to store the gzip compression results.

Gzip_comp_level

Syntax: Gzip_comp_level 1..9
Default value: Gzip_comp_level 1
Scopes: HTTP, server, location
gzip compression ratio, 1 compression than the minimum processing speed is the fastest, 9 compression than the largest but processing the slowest (faster transmission but more CPU consumption).

Gzip_min_length

Syntax: gzip_min_length length
Default value: Gzip_min_length 0
Scopes: HTTP, server, location
Sets the minimum number of bytes to allow compression, and the number of page bytes is obtained from the Content-length in the header header.
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. namely: Gzip_min_length 1024

Gzip_http_version

Syntax: Gzip_http_version 1.0|1.1
Default value: Gzip_http_version 1.1
Scopes: HTTP, server, location
Identifies the protocol version of HTTP. Because some early browsers or HTTP clients may not support gzip self-extracting, users will see garbled, so it is necessary to make some judgments. Note: 21st century has come, now in addition to similar to the spiders such as Baidu does not support self-extracting, 99.99% of the browser basically support gzip decompression, so you can not set this value, keep the system by default.

Gzip_proxied

Syntax: gzip_proxied [Off|expired|no-cache|no-store|private|no_last_modified|no_etag|auth|any] ...
Default value: Gzip_proxied off
Scopes: HTTP, server, location
Nginx is enabled as a reverse proxy, turning on or off the results returned by the backend server, if the backend server must return header header containing "Via".

off– shutdown All proxy result data compression
expired– Enable compression If header header contains "Expires" header information
no-cache– Enable compression If header header contains "Cache-control:no-cache" header information
no-store– Enable compression If header header contains "Cache-control:no-store" header information
private– Enable compression If header header contains "Cache-control:private" header information
no_last_modified– Enable compression If header header does not contain "last-modified" header information
no_etag– Enable compression If header header does not contain "ETag" header information
auth– Enable compression If header header contains "Authorization" header information
any– Enable compression unconditionally

Gzip_types

Syntax: Gzip_types mime-type [Mime-type ...]
Default value: Gzip_types text/html
Scopes: HTTP, server, location
Matches the MIME type for compression, regardless of whether the "text/html" type is always compressed.
Note: If used as an HTTP server, include the file type profile in the primary configuration file

Copy Code code as follows:

http
{
Include Conf/mime.types;
......
}

If you want to compress a regular file type, you can write this.
Copy Code code as follows:

http
{
Include Conf/mime.types;

gzip on;
Gzip_min_length 1000;
Gzip_buffers 4 8k;
Gzip_http_version 1.1;
Gzip_types text/plain application/x-javascript text/css text/html application/xml;

......
}


By default, Nginx gzip compression is turned off
At the same time, Nginx only compresses text/html by default
So, the instructions for opening gzip are as follows:
Copy Code code as follows:

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 picture to also turn on gzip compression, use the following paragraph:
Copy Code code as follows:

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

Attention:

1. One of the gzip_http_version settings, its default value is 1.1, that is, the http/1.1 protocol will be a request for gzip compression, if we use the Proxy_pass for reverse proxy, then nginx and back-end upstream The server is communicated with the http/1.0 protocol.

Copy Code code as follows:

This module makes the it possible to 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 are 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 cache Server through the reverse proxy, and the front-end Nginx does not turn on gzip, at the same time, there is no gzip_http_ on the nginx of our backend Version is 1.0, then the cache URL will not be gzip compressed

2. The Gzip_disable setting is to disable IE6 gzip compression and also because of the IE6 of the cups
IE6 some version of the GZIP compression support is very bad, will cause the page of suspended animation, today's product students tested this problem, later debugging, found that the IMG after gzip caused by the IE6 of suspended animation, the IMG after the gzip compression removed on the normal, In order to ensure that other IE6 versions are not problematic, the gzip_disable settings are added.

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.