Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
WangScaler: A writer with heart.
Declaration: uneducated, if there is a mistake, kindly correct.
Before, I introduced how to build my blog by hand, but did not mention how to deploy it. At first, my blog was simply deployed on Nginx. Later, as the number of blogs increased, there was no money to increase the bandwidth of the server, so the access became slower and slower, and even couldn’t load after three or four minutes. Nginx GZIP. When the configuration is finished, it is found to be about 10s, which is really a good thing.
Introduction to the
GZIP, as its name suggests, compresses and transfers files. Images, videos, large files are not recommended to use compression, compression needs to occupy your server resources, compression effect is not big. If there are a lot of pictures in the article, I suggest using a graphic bed to store your pictures. For additional features of nginx, see my previous nginx article on common operations.
Nginx configuration
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6].";
gzip_vary on;
gzip_static on;
Copy the code
Note: this section is configured under the HTTP layer, not the server. Personally tested the configuration does not work under server.
- Gzip_min_length: files smaller than this value will not be compressed.
- Gzip_buffers: Sets the requested memory size. Here are four blocks of memory in the unit of 16K, that is, applying for 16K x 4 memory space.
- Gzip_comp_level: The lower the compression level, the lower the compression ratio and the higher the compression speed.
- Gzip_types: file types to be compressed.
- Gzip_disable: Specifies that some browsers do not require compression, such as IE5.5 and IE6 SP1, using the mSIE6 parameter to disable compression
gzip
Compression. - Gzip_vary: adds the response header “Vary: accept-encoding”
Check whether the configuration is successful
After restarting Nginx, visit the blog. Content-encoding: gzip: Content-encoding: gzip: Content-encoding: gzip: Content-encoding: gzip: Content-encoding: gzip: Content-encoding: gzip: Content-encoding: gzip
The last
I think nginx can compress and transfer your files, but the compression process must also use your server resources, so it is recommended to manually use the command to compress resources in advance. For example, gzip Assets /js/*, it is also very difficult to manually compress files every time. Next time, I will show you how to use plug-ins to automatically compress files during compilation.
Four, must see related articles
- 1. Teach you how to build your own blog
- 2. Make your website HTTPS
Come all come, click “like” and then go!
Follow WangScaler and wish you a promotion, a raise and no bucket!