Original address: haifeiWu and his friends blog address: www.hchstudio.cn welcome to reprint, reprint please indicate the author and source, thank you!

It’s been a long time since I wrote a blog, but this habit can’t be lost, just a hydrological record of nginx non-stop version upgrade and configuration of gzip compression optimization website access experience process.

origin

What is hydrology? The author’s definition of hydrology is a large number of baidu searches, but it is always messy. Only by carefully sorting, can we really solve the problem, which is also the reason why the author wrote this article.

The opening

Nginx non-stop upgrade

Download the stable version of Nginx

Wget HTTP: / / http://nginx.org/download/nginx-1.14.1.tar.gzCopy the code

2. Compile Nginx

Do not make install during compilation.

# decompressionThe tar - ZXVF nginx - 1.14.1. Tar. Gz# compiler Nginx
cdNginx - 1.14.1Configure the module to be loaded
./configure --with-http_ssl_module
Do not make install
make
Copy the code

3. Back up the originalnginxScript, replaced by the newly generated one compiled

After backing up the original data, execute the following script to override the NgXIN executable.

cp -rfp objs/nginx /usr/local/nginx/sbin/
Copy the code

3. Perform the upgrade

The following command should be executed in the original make directory.

make upgrade
Copy the code

Configure gzip compression for Nginx

This configuration is relatively simple, modify the nginx.conf file to add the following content.

gzip on;                     # open Gzip
gzip_min_length  1k;         # Do not compress the critical value, greater than 1K compression
gzip_buffers     4 16k;      
gzip_comp_level 8;           # Compression level

The type of file to compress
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;
Copy the code

Then restart Nginx

./nginx -s reload
Copy the code

The final chapter

Of course, in addition to gzip can achieve compression, there is a Google Dad supported more powerful compression algorithm, called Brotli, you can work on it sometime.