Nginx start, restart, and close the command

Source: Internet
Author: User
Tags nginx server pkill
Stop operation
The stop operation is performed by sending a signal to the nginx process (for more information about the signal, see the Linux chapter ).
Step 1: query the nginx master process number
PS-Ef | grep nginx
Find the master process in the process list. Its number is the master process number.
Step 2: send signals
Stop nginx with ease:
Kill-Quit master process number
Stop nginx quickly:
Kill-term master process number
Force stop nginx:
Pkill-9 nginx

In addition, if the PID file storage path is configured in nginx. conf, the file stores the nginx main process number. If no PID file is specified, the file is placed in the nginx logs directory. With the PID file, we do not need to first query the main process Number of nginx, but directly send a signal to nginx. The command is as follows:
Kill-signal type '/usr/nginx/logs/nginx. PID'

Smooth restart
If you change the configuration, restart nginx. Do you need to disable nginx before enabling nginx? No. You can send a signal to nginx to restart nginx smoothly.
Smooth restart command:
Kill-HUP enters the title or process number file path

Or use

/Usr/nginx/sbin/nginx-s reload

 

 

Note: After modifying the configuration file, check whether the modified configuration file is correct to avoid nginx errors affecting the stable running of the server. The command to determine whether the nginx configuration is correct is as follows:
Nginx-t-c/usr/nginx/CONF/nginx. conf

Or

/Usr/nginx/sbin/nginx-T

 


Smooth upgrade
If the nginx server is running and the module needs to be upgraded, added, or deleted, we need to stop the server and modify it accordingly, so that the server will stop service for a period of time, nginx can be upgraded without stopping services, without affecting server operation.
Step 1:
If the nginx program is upgraded, replace the old program file with the new program. If the new program is compiled and installed, it is directly compiled into the nginx installation directory.
Step 2: Execute the command
Master process number or process File Name of the earlier version of kill-usr2
In this case, the old nginx main process will change its process file to. oldbin, and then execute the new nginx version. The old and new nginx servers run in the same city to process requests.
In this case, stop the old nginx version gradually and enter the following command:
Kill-master process Number of the old winch version
The old working process will exit as the task is completed, and the new nginx working process will gradually replace the old working process.

At this time, we can decide whether to use the new version or restore to the old version.
Do not reload the configuration to start the new/old Working Process
Kill-HUP old/new version master process number
Calmly close old/new processes
Kill-Quit old/new master process number
If an error is reported, the following command is used to shut down the old or new working process before closing the master process number:
Kill-term old/new worker process number

In this case, if you want to recover to the old version, you only need to operate the master process number of the new version in the previous steps, if you want to use the new version, perform the previous steps to operate the master process Number of the old version.

The above are some basic operations of nginx. I hope nginx can have a better way to handle these operations in the future. It is best to use nginx commands instead of sending system signals to the nginx process.Stop operation
The stop operation is performed by sending a signal to the nginx process (for more information about the signal, see the Linux chapter ).
Step 1: query the nginx master process number
PS-Ef | grep nginx
Find the master process in the process list. Its number is the master process number.
Step 2: send signals
Stop nginx with ease:
Kill-Quit master process number
Stop nginx quickly:
Kill-term master process number
Force stop nginx:
Pkill-9 nginx

In addition, if the PID file storage path is configured in nginx. conf, the file stores the nginx main process number. If no PID file is specified, the file is placed in the nginx logs directory. With the PID file, we do not need to first query the main process Number of nginx, but directly send a signal to nginx. The command is as follows:
Kill-signal type '/usr/nginx/logs/nginx. PID'

Smooth restart
If you change the configuration, restart nginx. Do you need to disable nginx before enabling nginx? No. You can send a signal to nginx to restart nginx smoothly.
Smooth restart command:
Kill-HUP enters the title or process number file path

Or use

/Usr/nginx/sbin/nginx-s reload

 

 

Note: After modifying the configuration file, check whether the modified configuration file is correct to avoid nginx errors affecting the stable running of the server. The command to determine whether the nginx configuration is correct is as follows:
Nginx-t-c/usr/nginx/CONF/nginx. conf

Or

/Usr/nginx/sbin/nginx-T

 


Smooth upgrade
If the nginx server is running and the module needs to be upgraded, added, or deleted, we need to stop the server and modify it accordingly, so that the server will stop service for a period of time, nginx can be upgraded without stopping services, without affecting server operation.
Step 1:
If the nginx program is upgraded, replace the old program file with the new program. If the new program is compiled and installed, it is directly compiled into the nginx installation directory.
Step 2: Execute the command
Master process number or process File Name of the earlier version of kill-usr2
In this case, the old nginx main process will change its process file to. oldbin, and then execute the new nginx version. The old and new nginx servers run in the same city to process requests.
In this case, stop the old nginx version gradually and enter the following command:
Kill-master process Number of the old winch version
The old working process will exit as the task is completed, and the new nginx working process will gradually replace the old working process.

At this time, we can decide whether to use the new version or restore to the old version.
Do not reload the configuration to start the new/old Working Process
Kill-HUP old/new version master process number
Calmly close old/new processes
Kill-Quit old/new master process number
If an error is reported, the following command is used to shut down the old or new working process before closing the master process number:
Kill-term old/new worker process number

In this case, if you want to recover to the old version, you only need to operate the master process number of the new version in the previous steps, if you want to use the new version, perform the previous steps to operate the master process Number of the old version.

The above are some basic operations of nginx. I hope nginx can have a better way to handle these operations in the future. It is best to use nginx commands instead of sending system signals to the nginx process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.