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

How to install php7 + nginx environment under centos6.6

This article describes how to install php7 + ngin...

Vue3 uses axios interceptor to print front-end logs

Table of contents 1. Introduction 2. Use axios in...

How to quickly create tens of millions of test data in MySQL

Remark: The amount of data in this article is 1 m...

HTML basics HTML structure

What is an HTML file? HTML stands for Hyper Text M...

How to draw the timeline with vue+canvas

This article example shares the specific code of ...

Detailed explanation of the use of nohup /dev/null 2>&1

nohup command: If you are running a process and y...

Several ways to schedule backup of MySQL database (comprehensive)

Table of contents 1. mysqldump command to back up...

mysql charset=utf8 do you really understand what it means

1. Let's look at a table creation statement f...

MySQL scheduled full database backup

Table of contents 1. MySQL data backup 1.1, mysql...

Simple implementation method of vue3 source code analysis

Table of contents Preface 🍹Preparation 🍲vue3 usag...

13 Most Frequently Asked Vue Modifiers in Interviews

Table of contents 1. lazy 2.trim 3.number 4.stop ...

Solution to the long delay of MySQL database master-slave replication

Preface The delay of MySQL master-slave replicati...

The whole process of developing a Google plug-in with vue+element

Simple function: Click the plug-in icon in the up...