Detailed explanation of Nginx version smooth upgrade solution

Detailed explanation of Nginx version smooth upgrade solution

background:

Since the nginx version in the load balancing test server is too low and there is a security vulnerability, after querying the relevant vulnerability repair information, it is necessary to upgrade the nginx version to repair the vulnerability.

Nginx smooth upgrade solution

1. Introduction to the version used in this case

Old version nginx-1.12.2.tar.gz

New version nginx-1.20.1.tar.gz

2. nginx-1.12.2 is the current running version


Set port 8080 and modify the homepage index.html. You can still access it after a smooth upgrade.

3. Unzip the new version nginx-1.20.1.tar.gz, compile and install it in the directory of the old version nginx-1.12.2, run the original nginx.conf configuration file, and execute as follows

./configure --prefix=/usr/local/nginx-1.12.2 --conf-path=/usr/local/nginx-1.12.2/nginx.conf --pid-path=/usr/local/nginx-1.12.2/nginx.pid --user=ngadm --group=ngadm --with-http_stub_status_module --without-http_rewrite_module 

make && make install

4. After completion, version 1.20.1 will automatically generate a new nginx binary file in the original sbin directory, and the old nginx will be automatically replaced with nginx.old

5. Smooth upgrade

Nginx has very powerful control over processes and can control processes through signal instructions. Commonly used signals are:

  • -QUIT, close the process after the table has processed the current request.
  • -HUP means reloading the configuration, that is, closing the original process and starting a new working process. This operation will not interrupt the user's access request, so Nginx can be restarted smoothly through this signal.
  • -USR2, used to smoothly upgrade executable programs.
  • -WINCH, gracefully shut down the worker process.

According to the nginx process control signal, execute as follows:

kill -USR2 38323 (the old process PID is 38323)
ps -ef |grep nginx 

Switch to the new master process and close the old worker process. Note that the old master process still exists. Execute as follows:

kill –WINCH 38323 (the old process PID is 38323)
ps -ef |grep nginx 

Check the current version

sbin/nginx -v 

The upgrade was completed successfully.

Note: At this time, the masterPID of the new version of nginx is 41063. At the same time, the master process of the old version (the old process PID is 38323) also exists. If you do not need to roll back, you can execute the old process exit operation as follows:

kill –QUIT 38323

Fallback steps

There are two types of rollback operations:

1. Back up the old version of nginx in advance. If there is a problem, just copy the old version back to the /usr/local directory and restart the old version of nginx. Execute as follows:

killall nginx
cp nginx-1.12.2.bak nginx-1.12.2
/usr/local/nginx-1.12.2/sbin/nginx –c /usr/local/nginx-1.12.2/nginx.conf

Check nginx status ps –ef |grep nginx

2. When the master process of the new version of nginx and the master process of the old version exist at the same time, execute the following:

Switch back to the old version of the master process

kill -HUP old masterPID 

Close the master process of the new version of nginx, and change the nginx.old (old version nginx binary file) in the original sbin directory back to nginx to manage nginx.

kill -WINCH new masterPID
kill -QUIT new masterPID
cp /usr/local/nginx-1.12.2/sbin/nginx.old /usr/local/nginx-1.12.2/sbin/nginx 

Confirm again that the nginx version has returned to the original version

sbin/nginx -v 

Summarize

This is the end of this article about the smooth upgrade solution for Nginx versions. For more relevant content about smooth upgrade of Nginx versions, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Example of how to upgrade nginx to support HTTP2.0
  • How to smoothly upgrade and rollback Nginx version in 1 minute
  • How to upgrade nginx to support http2
  • Some suggestions for improving Nginx performance
  • Nginx service installation and software upgrade

<<:  Detailed usage of MYSQL row_number() and over() functions

>>:  Detailed explanation of the alternative implementation code of CSS vertical centering (unconventional)

Recommend

Detailed tutorial on installing VirtualBox and Ubuntu 16.04 under Windows system

1. Software Introduction VirtualBox VirtualBox is...

HTML css js implements Tab page sample code

Copy code The code is as follows: <html xmlns=...

How to install mysql in docker

I recently deployed Django and didn't want to...

On good design

<br />For every ten thousand people who answ...

What you need to know about MySQL auto-increment ID

Introduction: When using MySQL to create a table,...

How to manage large file uploads and breakpoint resume based on js

Table of contents Preface Front-end structure Bac...

Table setting background image cannot be 100% displayed solution

The following situations were discovered during d...

Angular framework detailed explanation of view abstract definition

Preface As a front-end framework designed "f...

MySQL should never write update statements like this

Table of contents Preface cause Phenomenon why? A...

Design Theory: A Method to Understand People's Hearts

<br />Once, Foyin and Mr. Dongpo were chatti...

MySQL json format data query operation

The default table name is base_data and the json ...

Basic operations of mysql learning notes table

Create Table create table table name create table...

How to implement gzip compression in nginx to improve website speed

Table of contents Why use gzip compression? nginx...

MySQL 8.0.25 installation and configuration tutorial under Linux

The latest tutorial for installing MySQL 8.0.25 o...