The gzip module of Nginx is built-in. Add the following configuration in http:
Gzip on;
Gzip_min_length 5 k;
Gzip_buffers 4 16 k;
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 image/jpeg image/gif image/png;
Gzip_vary on;
Note:
Gzip on | off
# Default value: gzip off
# Enable or disable the gzip module
Gzip_static on | off
# Nginx static file processing module
# This module can read pre-compressed gz files, which can reduce the CPU resource consumption for gzip compression each request. After this module is enabled, nginx first checks whether there are files ending with the gz request for static files. If yes, the content of the gz file is directly returned. To be compatible with browsers that do not support gzip, the original static files and gz files must be retained when the gzip_static module is enabled. In this way, the disk space will be greatly increased when there are a large number of static files. We can use nginx's reverse proxy function to retain only the gz file.
# Google "nginx gzip_static"
Gzip_comp_level 4
# Default value: 1 (4 is recommended)
# Gzip compression ratio/compression level. The compression level is 1-9. The higher the level, the higher the compression ratio. Of course, the longer the compression time (fast transmission but cpu consumption ).
Gzip_buffers 4 16 k
# Default value: gzip_buffers 4 4 k/8 k
# 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 it 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_types mime-type [mime-type...]
# Default value: gzip_types text/html (js/css files are not compressed by default)
# Compression type, matching MIME type for compression
# Cannot use the wildcard text /*
# (Whether or not specified) text/html has been compressed by default
# For more information about the compressed text files, see conf/mime. types.
Gzip_min_length 1 k
# Default value: 0. Most pages are compressed.
# Sets the minimum number of page bytes that can be compressed. The number of page bytes is obtained from the Content-Length in the header.
# It is recommended to set the size to 1 kb. Smaller than 1 KB may increase the pressure. That is, gzip_min_length 1024
Gzip_http_version 1.0 | 1.1
# Default value: gzip_http_version 1.1 (that is, gzip compression is performed for HTTP/1.1 Requests)
# 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: 99.99% of browsers basically support gzip decompression, so you do not need to set this value to keep the system default value.
# Suppose we use the default value 1.1. If we use proxy_pass for reverse proxy, the nginx and the backend upstream server communicate with each other using the HTTP/1.0 Protocol, if we use nginx as the Cache Server through reverse proxy, and the front-end nginx does not enable gzip, at the same time, we do not set gzip_http_version to 1.0 on the backend nginx, the Cache url will not be compressed by gzip.
Gzip_proxied [off | expired | no-cache | no-store | private | no_last_modified | no_etag | auth | any]...
# Default value: off
# Enable Nginx when it is used as a reverse proxy. Enable or disable the results returned by the backend server, and ensure that the backend server must return headers 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_vary on
# It has something to do with the http header. Add a vary header for the proxy server. Some browsers support compression and some do not support compression, so avoid wasting and compressing unsupported ones, therefore, we can determine whether compression is required based on the HTTP header of the client.
Gzip_disable "MSIE [1-6]."
# Disable gzip compression for IE6 because IE6. Of course, IE6 is still widely used, so you can set it to "MSIE [1-5]."
# Some versions of IE6 have poor support for gzip compression, which may lead to the death of the page. Today, our product team has tested this problem.
After debugging, it was found that img gzip had caused IE6 to be suspended. After gzip compression of img was removed, it would be normal.
To ensure that other IE6 versions are normal, we recommend that you add gzip_disable settings.
About SEO:
Some people say that Baidu's support for Gzip is not good enough, and they are worried about the impact of indexing and SEO. After Baidu consulted the relevant information, it found that Baidu has made a report specifically on this issue, stating that Baidu supports Gzip.
Does gzip compression enabled on the server affect the crawling and indexing volume of spider images?
When the server enables gzip compression, it will not affect the spider capture. We will use the compression method to capture. It can also save the site's network traffic.