Nginx Stop and smooth restart

Source: Internet
Author: User

Nginx's Stop

the stop operation is done by sending a signal to the nginx process.
Step 1: Query the Nginx main process number
Ps-aux | grep nginx
find the master process in the list of processes, whose number is the main process number.
Step 2: Send a signal
calmly stop nginx:
kill-quit main process number
Quick Stop Nginx:
kill-term main process number
Force stop Nginx:
pkill-9 Nginx
In addition, if the nginx.conf configuration of the PID file storage path, the file is stored in the Nginx main process number, if not specified in the Nginx logs directory. With the PID file, we do not have to query the Nginx main process number, and directly to the nginx sent a signal, the command is as follows:
kill-Signal type '/usr/nginx/logs/nginx.pid '

Smooth restart of Nginx

(The installed Nginx is located in the/usr/local/nginx directory without modifying the installation path)

If you change the Nginx configuration file (nginx.conf), you want to restart Nginx, you can send the system signal to the NGINX main process of the way to do. However, before restarting, to confirm that the Nginx configuration file syntax is correct, you can test the configuration file correctly with the following command:

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

If the configuration file is incorrect, the screen will prompt for the first few lines of the configuration file:

Nginx:[emerg] Invalid number of arguments in "autoindex" directive in/usr/local/nginx/conf/nginx.conf:29

Nginx:configuration file/usr/local/nginx/conf/nginx.conf Test Failed

If the configuration file is correct, the screen will prompt for two lines of information:

The configuration file/usr/local/nginx/conf/nginx.conf syntax is OK

Configuration file/usr/local/nginx/conf/nginx.conf test is successful

At this point, you can smoothly reboot:

For Nginx version prior to 0.8.x kill-hup ' cat/usr/local/nginx/nginx.pid '

Or kill-hup The main process number as if it were a stop operation

For the version after Nginx 0.8.x /usr/local/webserver/nginx/sbin/nginx-s Reload

Smooth Upgrade
If the server is running Nginx to upgrade, add or remove modules, we need to stop the server and make the corresponding changes, so that the server will stop the service for a period of time, Nginx can be in the case of non-stop operation of various upgrade actions without affecting the server running.
Step 1:
If you upgrade the Nginx program, first replace the old program files with the new program, compile the installation of the new program directly compiled into the Nginx installation directory.
Step 2: Execute the command
KILL-USR2 The main process number or process file name of the legacy program
At this point the old Nginx master process will rename its process file to. oldbin, then execute the new version of Nginx. The old and new Nginx municipal run and process the request together.
To gradually stop the old version of Nginx, enter the command:
kill-winch Old Moderator process number
Slowly the old work process will be completed with the completion of the task to exit, the new version of Nginx work process will gradually replace the old version of the work process.
At this point, we can decide whether to use the new version or revert to the previous version.
Start a new/old worker process without overloading the configuration
kill-hup old/New master process number
Calmly close the old/new process
kill-quit old/New master process number
If there is an error at this point, and the process is not finished, use the following command to close the old/new worker process before closing the main process number:
kill-term old/new worker process number
This way down, if you want to revert to the old version, only a few of the above steps are the operation of the new version of the main process number, if you want to use the newer versions of the above steps to operate the old moderator process number on the line.

Attached: Nginx signal control

Nginx supports the following types of signals:

Term,int Quick Close

QUIT calmly close

HUP smooth Restart, reload configuration file

USR1 reopen log file for larger use when cutting logs

USR2 Smooth upgrade Gram Execution program

WINCH gracefully close the work process


Nginx Stop and smooth restart

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.