Nginx start, stop, smooth start, smooth upgrade

Source: Internet
Author: User

Nginx Start-up

Start Nginx, you can execute the command (the default installation location):
/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
The parameter "-C" specifies the path to the configuration file, and if not, Nginx will load the ngin.conf in the Conf subdirectory of its installation directory by default.

Nginx's Stop

Nginx Stop method has many kinds, usually send the system signal to the NGINX main process to stop Nginx.
We use the PS command to find the main process number of Nginx

ps -ef |grep nginx

We can see that the note information is "master Process" which represents the main process. is a child process for "worker".

If you specify a path to the PID file in nginx.conf, the file holds the Nginx main process number. If not specified, it is placed by default in the log directory of the Nginx installation directory. So we can also do this:

kill -信号类型 ‘/usr/local/nginx/logs/nginx.pid‘

Nginx supports the following types of signals:
Term,int: Quick Close
QUIT: Gracefully Close
HUP: Smooth Start
USR1: Reopen log file
USR2: Smooth Upgrade executable program
Einch: Gracefully close the worker process
(1) calmly stop Nginx

    kill -QUIT Nginx 主进程号

(2) Quick Stop Nginx

kill -TERM Nginx主进程号

(3) Force stop all Nginx processes

pkill -9 nginx
The smooth start of nginx

Kill-hup Nginx Main process number

Nginx Smooth Upgrade

When you need to upgrade a running Nginx, add/Remove server modules, you can replace the old version of the executable program with the new version, the recompiled Nginx executables without interruption. The steps are as follows:
(1) Back up the old executable program
(2) Send the following instructions

kill -USR2 旧的版本nginx主进程号

(3) The old version of Nginx's main process will rename his PID file to. Oldbin. Then execute the new version of the Nginx executable program. Start the new master process and the new worker process in turn.
(4) The old and new versions of Nginx will run at the same time, processing the input request together. To gradually stop an old nginx instance, you need to send a winch signal to the old master process, and then his work process is closed gracefully:

kill -WINCH 旧版本的主进程号

(5) After a period of time, the old worker process exits after all the connected requests have been processed, and only new worker processes are processed to process the input requests.
(6) We can decide whether to use the new version or revert to the old version.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Nginx start, stop, smooth start, smooth upgrade

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.