Home > Backend Development > PHP Tutorial > Analysis of GZip configuration parameters in Nginx server

Analysis of GZip configuration parameters in Nginx server

不言
Release: 2023-04-01 18:58:01
Original
1875 people have browsed it

This article mainly introduces the detailed explanation of GZip configuration parameters in Nginx server, that is, using GZip to compress website page data. Friends in need can refer to it

gzip (GUN-ZIP) is a compression technology , the page size after gzip compression can be reduced to 30% or less of the original size.

Users will browse the page faster. The gzip compressed page needs to be supported by both the server and the browser. The server-side compression is transmitted to the

browser for decompression and parsing. Now most Most browsers already support parsing gzip pages

gzip usage environment: http, server, location, if (x), generally I define it in http{…..} of nginx.conf Time
gzip on;

Turn on gzip off off
gzip_min_length 1k;

Set the minimum page bytes allowed for compression ( Obtained from the Content-Length of the header header) It is recommended to be greater than 1k
gzip_buffers 4 16k;

is based on 16k as the unit, and applies for memory in 4 times the original data size in 16k as the unit
gzip_http_version 1.1;

Identify the version of http protocol. Early browsers may not support gzip self-extraction, and users will see garbled characters
gzip_comp_level 2;

Level 1-9 The smallest compression is the fastest but consumes cpu
gzip_types text/plain application/x-javascript text/css application/xml;

Match compression type
gzip_vary on;

Enable response header "Vary: Accept-Encoding"

gzip_proxied off;

Enable when nginx is used as a reverse proxy, off (turn off the compression of all proxy result data), expired (enable compression, if the header header includes "Expires" header information), no-cache (enable compression, in the header header) Contains "Cache-Control: no-cache"), no-store (enables compression, the header contains "Cache-Control: no-store"), private (enables compression, the header contains "Cache-Control: private" ), no_last_modefied (enable compression, the header does not contain "Last-Modified"), no_etag (enable compression, if the header does not contain "Etag" header information), auth (enable compression, if the header contains "Authorization" header information)
gzip_disable msie6;

(IE5.5 and IE6 SP1 use the msie6 parameter to disable gzip compression) Specify which browsers do not require gzip compression (will be used with User- Agents for matching), relying on the PCRE library

##gzip
Determine whether to enable the gzip module
example:

gzip on;
Copy after login

gzip_buffers
Set the size of memory requested by gzip. Its function is to apply for memory space in multiples of the block size.
param2:int(k) The following unit is k
example:

gzip_buffers 4 8k;
Copy after login

gzip_comp_level
Set the gzip compression level. The lower the level, the faster the compression speed and the smaller the file compression ratio. On the contrary, the slower the speed, the larger the file compression ratio.
param:1-9
example:

gzip_com_level 1;
Copy after login

gzip_min_length
When the returned content is greater than this value, gzip will be used for compression, in K, when the value is 0, all pages will be compressed
param:int
example:

gzip_min_length 1000;
Copy after login

gzip_types
Set the MIME type that needs to be compressed, non-set values ​​will not be compressed
param:text/html|application/x-javascript|text/ css|application/xml
example:

gzip_types text/html;
Copy after login

For most text-based sites, the content of the text itself accounts for the vast majority of the traffic. Although the volume of a single text is not large, if there are a large number, the traffic is still considerable. After enabling GZIP, the required traffic can be greatly reduced. The above code can be inserted into the configuration of the entire http {...} server, or into the server {...} of the virtual host or the location module below.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to quickly view nginx configuration files

The above is the detailed content of Analysis of GZip configuration parameters in Nginx server. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template