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

Two ways to use react in React html

Basic Use <!DOCTYPE html> <html lang=&qu...

Vue implements verification code countdown button

This article example shares the specific code of ...

Ubuntu20.04 VNC installation and configuration implementation

VNC is a remote desktop protocol. Follow the inst...

MySQL5.7 single instance self-starting service configuration process

1.MySQL version [root@clq system]# mysql -v Welco...

An example of how JavaScript can prevent duplicate network requests

Preface During development, we often encounter va...

How to redirect URL using nginx rewrite

I often need to change nginx configuration at wor...

Will CSS3 really replace SCSS?

When it comes to styling our web pages, we have t...

Introduction to the common API usage of Vue3

Table of contents Changes in the life cycle react...

JavaScript to implement login slider verification

This article example shares the specific code of ...

A brief analysis of the difference between static and self in PHP classes

Use self:: or __CLASS__ to get a static reference...

Solutions to MySql crash and service failure to start

I have been in contact with PHP for so long, but ...

HTML input box optimization to improve user experience and ease of use

In order to improve user experience and ease of us...

How to count down the date using bash

Need to know how many days there are before an im...

Vue.js implements timeline function

This article shares the specific code of Vue.js t...