One: the benefits of compression

Compression can reduce the size of HTTP replies, thereby reducing the response time of the Web server. Gzip is a widely used compression tool for Web servers that can reduce the size of HTTP replies by 50 to 30 percent. It not only improves the loading speed of web pages, but also saves server traffic.

Two: Nginx server enable Gzip compression method

Open the nginx.conf file and paste the following code into the file:

# Enable gzip
gzip on; 
# Enable gzip static compression
gzip_static on; 
#gzip cache size
gzip_buffers 4 16k;
# gzip HTTP versionGzip_http_version 1.1;#gzip compression level 1-10
gzip_comp_level 5;
#gzip compression typegzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg  image/gif image/png;Gzip_vary on is recommended for HTTP header Vary: accept-encoding.
Copy the code

Then, reload nginx.

systemctl restart nginx
Copy the code

Three: gzip_static function

Nginx already has gzip compression enabled by setting gzip on, but nginx uses dynamic compression. In the case of dynamic compression, nginx automatically compresses files into.gz files, which can achieve the same effect without configuring VUE.

But dynamic compression undoubtedly takes up the server’s resources to do so.

In contrast, Nginx provides a static compression mode, called gzip_static, in which nginx looks for the corresponding. Gz file and compresses the corresponding file only if it does not exist. This way, you don’t overuse the server resources.

The gzip_static function relies on the http_gzip_STATIC_module module, which is not installed by default. You can install it using the method described above.

So whether to use dynamic compression or static compression is up to the reader.

For good suggestions, please enter your comments below.

Welcome to my blog guanchao.site