Detailed explanation of gzip configuration and configuration parameters in nginx

Source: Internet
Author: User
Tags nginx load balancing

I have been working on nginx Load Balancing for the last few days. After several days, I checked a lot of information on the Internet and found that most of the information is very general, or I am confused about it, many configuration parameters are not quite clear, which may cause inaccurate configuration. Now I will summarize my configuration over the past few days, from download to installation, to environment setup, as well as the configuration of Server Load balancer, detailed explanations of parameters, and subsequent session sharing, we will introduce them one by one, hoping to help new users who are interested in nginx.
This article references: http://wiki.nginx.org/NginxChsHttpGzipModule
Ngx_http_gzip_module:
This module supports online real-time compression of output data streams

_ Example __

: Gzip on;
: Gzip_min_length 1000;
: Gzip_proxied expired no-Cache no-store private auth;
: Gzip_types text/plain application/XML;
The built-in variable $ gzip_ratio can obtain the gzip compression ratio.

Command
[# Gzip]
[# Gzip_buffers]
[# Gzip_comp_level]
[# Gzip_min_length]
[# Gzip_http_version]
[# Gzip_proxied]
[# Gzip_types]
Template: Anchor

Gzip
Syntax: gzip on | off
Default Value: gzip off
Scope: HTTP, server, location, if (x) Location
Enable or disable the gzip Module

Gzip_buffers
Syntax: gzip_buffers number size
Default Value: gzip_buffers 4 4 K/8 K
Scope: HTTP, server, location
Set the system to obtain several units of cache for storing gzip compressed result data streams. For example, 4 K indicates that 4 K is used as the unit, and 4 times the size of raw data is used as the unit to apply for memory. 4 8 K represents 8 K as the unit, according to the size of raw data 4 times the size of 8 K applied for memory.
If this parameter is not set, the default value is to apply for a memory space of the same size 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
Scope: HTTP, server, location
Gzip compression ratio: 1. The minimum compression ratio is the fastest, 9. The maximum compression ratio is the lowest, but the processing speed is the slowest (fast transmission but CPU consumption ).

Gzip_min_length
Syntax: gzip_min_length Length
Default Value: gzip_min_length 0
Scope: HTTP, server, location
Sets the minimum number of page bytes that can be compressed. The number of page bytes is obtained from Content-Length in 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. That is, gzip_min_length 1024

Gzip_http_version
Syntax: gzip_http_version 1.0 | 1.1
The default value is gzip_http_version 1.1.
Scope: HTTP, server, location
Identify the HTTP protocol version. Some early browsers or HTTP clients may not support gzip self-extracting, and users will see garbled characters, so it is necessary to make some judgments. Note: Since the 21st Century, self-extracting is not supported except for items like Baidu's spider (Baidu is Sx, so I won't talk about it ), 99.99% of browsers basically support gzip decompression, so you don't need to set this value to keep the system default value.

Gzip_proxied
Syntax: gzip_proxied [Off | expired | no-Cache | no-store | private | no_last_modified | no_etag | auth | any]...
Default Value: gzip_proxied off
Scope: HTTP, server, location
Nginx is enabled when it is used as a reverse proxy. If you enable or disable the results returned by the backend server, the backend server must return the header containing ".
Off-Disable compression of All proxy result data
Expired-enable compression. If the header contains "expires" header information
No-Cache-enable compression. If the header contains "cache-control: No-Cache" header information
No-store-enable compression. If the header contains "cache-control: No-store" header information
Private-enable compression. If the header contains "cache-control: Private" header information
No_last_modified-enable compression. If the header does not contain "last-modified" header information
No_etag-enable compression. If the header does not contain the "etag" header information
Auth-enable compression. If the header contains "Authorization" header information
Any-enable compression unconditionally

Gzip_types
Syntax: gzip_types mime-type [mime-type...]
Default Value: gzip_types text/html
Scope: HTTP, server, location
The MIME type is compressed (whether specified or not). The "text/html" type is always compressed.
Note: If it is used as an HTTP server, the main configuration file must contain the file type configuration file.
HTTP
{
Include CONF/mime. types;
......
}

If you want to compress the regular file type, you can write it like this.
HTTP
{
: Include CONF/mime. types;

: Gzip on;
: Gzip_min_length 1000;
: Gzip_buffers 4 8 K;
: Gzip_http_version 1.1;
: Gzip_types text/plain application/X-JavaScript text/CSS text/HTML Application/XML;

:......
}
If you have reproduced, please indicate the original source: http://blog.csdn.net/jessonlv/article/details/8016284

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.