1. 程式人生 > >Nginx的啟動、停止和重啟

Nginx的啟動、停止和重啟

pkill con 地址 參考 tps roo 停止 oot load

啟動

啟動代碼格式:nginx安裝目錄地址 -c nginx配置文件地址

例如:

[root@sijizhen sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

停止

nginx有三種停止方式:

從容停止

1.查看進程 ps -ef|grep nginx

[root@sijizhen sbin]# ps -ef|grep nginx
root      9862     1  0 01:04 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    9863  9862  0 01:04 ?        00:00:00 nginx: worker process                                          
root      9886  1612  0 01:15 pts/0    00:00:00 grep nginx

2.殺死進程

[root@sijizhen sbin]# kill -QUIT 9862

快速停止

1、查看進程號

[root@sijizhen sbin]# ps -ef|grep nginx
root      9892     1  0 01:17 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    9893  9892  0 01:17 ?        00:00:00 nginx: worker process                                          
root      9895  1612  0 01:18 pts/0    00:00:00 grep nginx

2.殺死進程

[root@sijizhen sbin]# kill -TERM 9892

強制停止

[root@sijizhen sbin]# pkill -9 nginx

重啟

1、驗證nginx配置文件是否正確

方法一:進入nginx安裝目錄sbin下,輸入命令./nginx -t

[root@sijizhen sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

說明配置文件正確!

方法二:在啟動命令-c前加-t

[root@sijizhen sbin]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

2、重啟Nginx服務

方法一:進入nginx可執行目錄sbin下,輸入命令./nginx -s reload 即可

[root@sijizhen sbin]# ./nginx -s reload

方法二:查找當前nginx進程號,然後輸入命令:kill -HUP 進程號 實現重啟nginx服務

[root@sijizhen sbin]# ps -ef|grep nginx
root      9928     1  0 01:24 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    9935  9928  0 01:25 ?        00:00:00 nginx: worker process                                          
root      9938  1612  0 01:26 pts/0    00:00:00 grep nginx
[root@sijizhen sbin]# kill -HUP 9928

參考:https://www.cnblogs.com/codingcloud/p/5095066.html

Nginx的啟動、停止和重啟