Nginx gzip module Enable and configure instructions _nginx

Source: Internet
Author: User
Tags auth gz file

The Nginx gzip module is built into, adding the following configuration to http:

Copy Code code as follows:
gzip on;
Gzip_min_length 5k;
Gzip_buffers 4 16k;
Gzip_http_version 1.0;
Gzip_comp_level 3;
Gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php imag E/jpeg image/gif image/png;
Gzip_vary on;

Configuration directive detailed Comment:

Gzip On|off
# Default value: gzip off
# turn on or off the gzip module

Gzip_static On|off

# Nginx Processing module for static files
# This module can read the pre compressed GZ file, which reduces the CPU resource consumption per request for gzip compression. When the module is enabled, Nginx first checks for files that have a request for a static file, GZ, and returns the contents of the GZ file directly. In order to be compatible with browsers that do not support gzip, enabling the Gzip_static module must retain both the original static and the GZ files. In this case, there will be a significant increase in disk space when there are a large number of static files. We can use the reverse proxy function of Nginx to keep only gz files.
# can Google "Nginx gzip_static" to learn more

Gzip_comp_level 4

# Default value: 1 (recommended option is 4)
# gzip Compression ratio/compression level, compression level 1-9, the higher the level of compression, of course, the longer the compression time (faster transmission but more CPU consumption).

Gzip_buffers 4 16k

# Default value: Gzip_buffers 4 4k/8k
# Set the system to get several units of cache to store the gzip compressed result 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_types Mime-type [Mime-type ...]

# Default value: Gzip_types text/html (default does not compress js/css files)
# compression type, matching MIME type for compression
# can't use wildcard characters text/*
# (whether or not specified) text/html default has been compressed
# Set which compressed type of text file to refer to Conf/mime.types

Gzip_min_length 1k

# Default value: 0, no matter how many pages compressed
# Sets the minimum number of bytes to allow for compression, and the number of page bytes is obtained from the Content-length in the header header.
# It is recommended to set the number of bytes larger than 1k, less than 1k may be more pressure. namely: Gzip_min_length 1024

gzip_http_version 1.0|1.1

# Default: Gzip_http_version 1.1 (that is, the request to the http/1.1 protocol will be gzip compressed)
# 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: 99.99% of browsers basically support Gzip decompression, so you can not set this value, keep the system by default.
# Assuming we are using the default value of 1.1, if we use Proxy_pass to reverse proxy, then Nginx and backend upstream server are communicating with the http/1.0 protocol, if we use Nginx to do the cache via the reverse proxy Server, and the front end of the Nginx does not turn on gzip, at the same time, our backend nginx on the gzip_http_version is not set to 1.0, then the cache URL will not be gzip compressed

gzip_proxied [Off|expired|no-cache|no-store|private|no_last_modified|no_etag|auth|any] ...

# Default value: Off
# Nginx is enabled as a reverse proxy, turns on or turns off the results returned by the backend server, matching the premise that the backend server must return the header that contains "Via".
Off-Closes all the 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_vary on

# and the HTTP header has a relationship, add a vary head, to the proxy server, and some browsers support compression, some do not support, so avoid wasting unsupported also compression, so according to the client's HTTP headers to determine whether the need to compress

Gzip_disable "MSIE [1-6]."

# disables IE6 gzip compression and is also due to the IE6 of Cups. Of course, IE6 is still widely present, so here you can also set it to "MSIE [1-5]."
# Some versions of IE6 to gzip compression support is very bad, will cause the death of the page, today's product students to test the problem
Later debugging, found that the IMG after GZIP caused IE6 of suspended animation, to the IMG gzip compression removed after the normal
To ensure that other IE6 versions are not problematic, it is recommended that you add gzip_disable settings

About SEO:
Some people say that Baidu's support for Gzip is not good enough to worry about the impact of the collection and SEO, Baidu access to relevant data found in Baidu specifically for the issue of the report, said Baidu is supporting Gzip.
Does the server turn on gzip compression will affect spiders crawl and collect quantity?
The server turns on gzip compression, will not affect the spider crawl, we will be in the way of compression to crawl. And also can save the site network traffic.

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.