Home >Backend Development >PHP Tutorial >nginx start, restart, shut down commands

nginx start, restart, shut down commands

WBOY
WBOYOriginal
2016-08-08 09:32:411214browse

nginx startup command is:

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

-c specifies the path to the configuration file. Without -nginx, it will automatically Load the configuration file from the default path.


After studying the nginx help document, I found that there is the -s parameter to manage the nginx service:
# /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

So execute
# /usr/local/nginx/sbin /nginx -s reload
nginx has been restarted successfully

The following is the reproduced content

nginx startup, restart, shutdown commands

Stop operation
Stop operation is by sending a signal to the nginx process (what is a signal please (See linux article)
Step 1: Query the nginx main process number
ps -ef | grep nginx
Look for the master process in the process list, and its number is the main process number.
Step 2: Send signal
Stop Nginx gracefully:
kill -QUIT main process number
Quickly stop Nginx:
kill -TERM main process number
Force stop Nginx:
pkill -9 nginx

In addition, if the pid file storage path is configured in nginx.conf, the file will store the Nginx main process ID. If not specified, it will be placed in the nginx logs directory. With the pid file, we don’t need to query the main process number of Nginx first, 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, 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 Enter the name or process number file path

or use

/usr/nginx/sbin/nginx -s reload

Note that after modifying the configuration file, the last It is best to check whether the modified configuration file is correct first, so as to avoid errors in Nginx after restarting, which will affect the stable operation 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 When the Nginx running on the server wants to upgrade, add or delete modules, we need to stop the server and make corresponding modifications. In this way, the server will stop serving for a period of time. Nginx can perform various upgrade actions without shutting down. Does not affect server operation.
Step 1:
If you upgrade the Nginx program, first replace the old program file with the new program. After compiling and installing, the new program will be compiled directly into the Nginx installation directory.
Step 2: Execute the command
kill -USR2 The main process number or process file name of the old version of the program
At this time, the old Nginx main process will rename its process file to .oldbin, and then execute the new version of Nginx. The new and old Nginx run together to process requests.
At this time, you need to gradually stop the old version of Nginx. Enter the command:
kill -WINCH old moderator process number
Slowly, the old working process will exit as the task is completed, and the new version of Nginx working process will gradually replace the old version of the working process. .
At this point, we can decide to use the new version or revert to the old version.
Start the new/old worker process without overloading the configuration
kill -HUP the old/new moderator process number
Close the old/new process calmly
kill -QUIT the old/new main process number
If an error is reported at this time, it will prompt whether there are any processes When finished, use the following command to first close the old/new working process, and then close the main process ID:
kill -TERM old/new working process ID
In this way, if you want to restore to the old version, you only need to follow the above steps The new moderator process ID. If you want to use the new version, just follow the above steps to the old moderator process ID.
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.

The above introduces the nginx startup, restart, and shutdown commands, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn