In this article, let's introduce Nginx Common operation commands in .
-h help Command to view help information
Direct execution Nginx The binary file can be
This mode will load by default /usr/local/conf/nginx.conf The configuration file
You can also specify the configuration file to load at startup time -c
/usr/local/nginx/sbin/nginx -c conf/nginx.conf
Of course, we can also specify when starting pid Storage location
/usr/local/nginx/sbin/nginx -g “pid /usr/local/nginx/nginx.pid;”
-g The constraint condition of the parameter is that the specified configuration item cannot be the same as nginx.conf Configuration items in conflict , Otherwise it won't start . Like the example above , Configuration items like this ：pid logs/nginx.pid, Can't exist in default nginx.conf Medium .
Another constraint is , With -g Way to start Nginx When the service executes other command lines , Need to put -g Parameters are also taken with , Otherwise, the configuration items may not match . for example , If you want to stop Nginx service , Then you need to execute the following code ：
/usr/local/nginx/sbin/nginx -g "pid /usr/local/nginx/nginx.pid;" -s stop
ps -ef | grep nginx
See if there is a corresponding nginx process
You can also check the corresponding pid file , You can see the corresponding master The process number of the process , Indicates that the service is started
Last nginx The default port is 80, At this time, we can access successfully in the browser, which can also indicate that the startup is successful
see master The way the process works
ps -ef | grep nginx
stop it Nginx There are many ways , Usually by sending a system signal to Nginx Main process way to stop Nginx
grammar ： kill Semaphore type master Process number
Easy to stop : allow Nginx The service completes the network request currently being processed , But no more new requests
kill -quit Process number
Stop quickly : Immediately stop the current Nginx All network requests being processed by the service
kill -term Process number
Execute the stop command , The process was killed immediately
Force to stop : This has to be done separately master The process and worker process
kill -9 Process number
The semaphore mode above stops , It's a little troublesome , We need to look up the corresponding master Process number , And then send the corresponding semaphore , At this point, we can stop in a more concise way
/usr/local/nginx/sbin/nginx -s stop
Use -s stop Can be forced to stop Nginx service .-s The parameter actually tells Nginx Program to the running Nginx The number of semaphores sent by the service ,Nginx Procedure passed nginx.pid In the document master Process of process ID, And then to the running master Process send TERM Signal to turn off quickly Nginx service .
If you want to Nginx The service can normally complete all current requests and then stop the service , Then you can use -s quit Parameter to stop the service .
/usr/local/nginx/sbin/nginx -s quit
The command with quick stop Nginx Service is different . When the service stops quickly ,worker Process and master The process will jump out of the loop immediately after receiving the signal , Withdraw from the process . and “ grace ” When the service stops , First, the listening port is turned off , Stop receiving new connections , Then finish processing all the connections that are currently being processed , Finally, exit the process .
If it changes Nginx Configuration file for .nginx.conf, Want to restart Nginx, First, we need to verify nginx.conf Is there any problem with the grammar of
There's no problem with grammar validation, we can pass -s reload To reload the configuration file
/usr/local/nginx/sbin/nginx -s reload
Get to reload by sending semaphores
kill -hup master Process number
Okay ,nginx The commonly used operation commands are introduced here , I believe you should be able to operate Nginx 了 ~