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

The difference between html Frame, Iframe and Frameset

10.4.1 The difference between Frameset and Frame ...

Solution to the problem that Docker container cannot be stopped or killed

Docker version 1.13.1 Problem Process A MySQL con...

The iframe frame sets the white background to transparent in IE browser

Recently, I need to frequently use iframe to draw ...

Using react-beautiful-dnd to implement drag and drop between lists

Table of contents Why choose react-beautiful-dnd ...

How to reset the initial value of the auto-increment column in the MySQL table

How to reset the initial value of the auto-increm...

Problems with index and FROM_UNIXTIME in mysql

Zero, Background I received a lot of alerts this ...

Introduction to NFS service construction under Centos7

Table of contents 1. Server 2. Client 3. Testing ...

Summary of Button's four Click response methods

Button is used quite a lot. Here I have sorted ou...

Textarea tag in HTML

<textarea></textarea> is used to crea...

After docker run, the status is always Exited

add -it docker run -it -name test -d nginx:latest...

Summary of practical skills commonly used in Vue projects

Table of contents Preface 1. Use $attrs and $list...

React+Antd implements an example of adding, deleting and modifying tables

Table of contents Table/index.js Table/model/inde...

Problems with nodejs + koa + typescript integration and automatic restart

Table of contents Version Notes Create a project ...

How to create Apache image using Dockerfile

Table of contents 1. Docker Image 2. Create an in...