Nginx Start, restart, shutdown commands

Source: Internet
Author: User
The Nginx startup command is:

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

-C Set the path to the configuration file, without-nginx the configuration file that automatically loads the default path.


After studying the Nginx help document, it is found that the Nginx service can be managed with the-s parameter:
#/usr/local/nginx/sbin/nginx-h
Nginx version:nginx/0.7.63
Usage:nginx [-?HVVT] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
-?,-H:this Help
-v:show Version and exit
-v:show version and configure options then exit
-t:test Configuration and exit
-S signal:send signal to a master process:stop, quit, reopen, reload
-P prefix:set Prefix path (default:/usr/local/nginx/)
-C filename:set configuration file (default:conf/nginx.conf)
-G Directives:set Global directives out of configuration file

Then execute
#/usr/local/nginx/sbin/nginx-s Reload
Nginx has been restarted successfully

Here is the content reproduced

Nginx start, restart, close command

Stop operation
The stop operation is done by sending a signal to the nginx process (see the Linux article for a signal)
Step 1: Query the Nginx main process number
Ps-ef | 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
If you change the configuration to restart Nginx, you need to turn off the nginx before opening? No, can send a signal to nginx, smooth restart.
Smooth restart command:
Kill-hup live in 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 the correct configuration file, so as not to restart after the Nginx error affecting the stable operation of the server. Determine if the Nginx configuration is the correct command 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 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.
Above is the Nginx some basic operation, I hope in the future nginx can have a better way to handle these operations, it is best to nginx command rather than send the system signal to the nginx process.


The above describes the Nginx start, restart, close command, including the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.