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

What are the common operation methods of nginx

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

Share

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

This article mainly introduces the relevant knowledge of "what are the common operation methods of nginx". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "what are the common operation methods of nginx" can help you solve the problem.

nginx start, restart, close command

stop operation

ps is required before stopping all processes of the current Nginx

Step 1: Query nginx main process number

ps -ef | grep nginx

Find the master process in the process list, and its number is the master process number.

Step 2: Send a signal to stop Nginx calmly:

kill -QUIT Main process number

Quick Stop Nginx

kill -$TERM main process number

Forcing Nginx to Stop:

pkill -9 nginx

In addition, if the pid file storage path is configured in nginx.conf, the file stores the main process number of Nginx. If not specified, it is placed in the logs directory of nginx. With the pid file, we do not need to query the main process number of Nginx first, but directly send a signal to Nginx, command as follows:

kill -Signal type '/usr/nginx/logs/nginx.pid'

graceful restart

If you change the configuration, you need to restart Nginx. Do you need to close Nginx first and then open it? No, you can send a signal to Nginx to restart smoothly.‎

Smooth restart command:

kill -HUP live title or process number file path

Or use:

/usr/nginx/sbin/nginx -s reload

Note that after modifying the configuration file, it is best to check whether the modified configuration file is correct, so as to avoid Nginx errors affecting the stable operation of the server after restarting.

To determine whether Nginx configuration is correct, the command is as follows:

nginx -t -c /usr/nginx/conf/nginx.conf

or

/usr/nginx/sbin/nginx -t

smooth upgrade

If the server is running Nginx to upgrade, add or delete modules, we need to stop the server and make corresponding modifications, so that the server will stop serving for a period of time, Nginx can be in the case of non-downtime Various upgrade actions without affecting the server operation.

Step 1: If you upgrade the Nginx program, replace the old program file with the new program first, and compile the new program directly into the Nginx installation directory.

Step 2: Execute Command

kill -Main process number or process file name of USR2 legacy program

At this point, the old Nginx master process will rename its own process file to.oldbin and execute the new Nginx. The old and new Nginx run in conjunction with the city, processing requests together.‎

At this point, to gradually stop the old version of Nginx, enter the command:

kill -WINCH old moderator process number

Slowly the old work process will exit with the completion of the task, the new version of Nginx work process will gradually replace the old version of the work process, at this time, we can decide to use the new version or restore to the old version.

Do not overload configuration to start new/old worker processes

kill -HUP old/new moderator process number

Close old/new processes calmly

kill -QUIT Old/New Master Process Number

If an error is reported at this time, prompt that there is still a process that has not ended, use the following command to close the old/new working process first, and then close the main process number:

Close main process number

kill -$TERM old/new job process number

In this way, if you want to restore to the old version, you only need the above steps to operate the new moderator process number, if you want to use the new version on the above steps to operate the old moderator process number on the line.

related commands

/usr/local/nginx-1.0.6/sbin/nginx //start nginx/usr/local/nginx-1.0.6/sbin/nginx-t //test the accuracy of nginx configuration files/usr/local/nginx-1.0.6/sbin/nginx-s reload //overload nginx/usr/local/nginx-1.0.6/sbin/nginx-s stop //close nginx/usr/local/nginx-1.0.6/sbin/nginx -V /view nginx installed modules/usr/local/nginx-1.0.6/sbin/nginx -v //view nginx version/usr/local/nginx/sbin/nginx-s reload //overload nginx on "what are the common operating methods of nginx" content introduced here, thank you for reading If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

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