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

Analysis of GZip configuration parameters in Nginx server

Jun 25, 2018 pm 01:47 PM
gzip nginx

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

See all articles