Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upgrade smoothly in nginx operation and maintenance

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to upgrade smoothly in nginx operation and maintenance". It is easy to understand and well organized. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to smooth upgrade in nginx operation and maintenance".

You can replace the old one with a new nginx executable (when upgrading a new version or adding / removing server modules) without interrupting the service-the new request will not be lost. (recommended study: nginx operation and maintenance)

First, replace the old one with a new executable (preferably with a backup), and then send a USR2 (kill-USR2pid) signal to the main process.

The main process renames its .pid file to .oldbin (for example: / usr/local/nginx/logs/nginx.pid.oldbin), then executes the new executable program, and then starts the new main process and the new worker process in turn:

PIDPPIDUSER%CPUVSZWCHANCOMMAND

331261root0.01164pausenginx:masterprocess/usr/local/nginx/sbin/nginx

3313433126nobody0.01368kqreadnginx:workerprocess (nginx)

3313533126nobody0.01380kqreadnginx:workerprocess (nginx)

3313633126nobody0.01368kqreadnginx:workerprocess (nginx)

3626433126root0.01148pausenginx:masterprocess/usr/local/nginx/sbin/nginx

3626536264nobody0.01364kqreadnginx:workerprocess (nginx)

3626636264nobody0.01364kqreadnginx:workerprocess (nginx)

3626736264nobody0.01364kqreadnginx:workerprocess (nginx)

At this point, two nginx instances will run at the same time, processing the input request together. To phase out the old instance, you must send a WINCH signal to the old main process, and then its working process will start shutting down calmly:

PIDPPIDUSER%CPUVSZWCHANCOMMAND

331261root0.01164pausenginx:masterprocess/usr/local/nginx/sbin/nginx

3313533126nobody0.01380kqreadnginx:workerprocessisshuttingdown (nginx)

3626433126root0.01148pausenginx:masterprocess/usr/local/nginx/sbin/nginx

3626536264nobody0.01364kqreadnginx:workerprocess (nginx)

3626636264nobody0.01364kqreadnginx:workerprocess (nginx)

3626736264nobody0.01364kqreadnginx:workerprocess (nginx)

After a period of time, the old worker process processes all connected requests and exits, and only the new worker process handles the input request:

PIDPPIDUSER%CPUVSZWCHANCOMMAND

331261root0.01164pausenginx:masterprocess/usr/local/nginx/sbin/nginx

3626433126root0.01148pausenginx:masterprocess/usr/local/nginx/sbin/nginx

3626536264nobody0.01364kqreadnginx:workerprocess (nginx)

3626636264nobody0.01364kqreadnginx:workerprocess (nginx)

3626736264nobody0.01364kqreadnginx:workerprocess (nginx)

At this point, because the old server has not yet turned off the socket it listens on, you can still restore the old server with the following steps:

Send a HUP signal to the old main process-it will start its worker process without reloading the configuration file

Send a QUIT signal to the new main process, asking it to shut down its working process calmly

Send a TERM signal to the new main process, forcing it to exit

If a new worker process cannot quit for some reason, send a KILL signal to it

After the new master process exits, the old master process removes the .oldbin prefix and reverts to its .pid file, so that everything is restored to before the upgrade.

If the upgrade is successful and you want to keep the new server, send a QUIT signal to the old main process to exit, leaving only the new server to run:

PIDPPIDUSER%CPUVSZWCHANCOMMAND

362641root0.01148pausenginx:masterprocess/usr/local/nginx/sbin/nginx

3626536264nobody0.01364kqreadnginx:workerprocess (nginx)

3626636264nobody0.01364kqreadnginx:workerprocess (nginx)

3626736264nobody0.01364kqreadnginx:workerprocess (nginx)

The above is all the contents of the article "how to upgrade smoothly in nginx operation and maintenance". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report