nginx服務(wù)的啟動(dòng) 停止和重啟

nginx 命令

啟動(dòng) nginx 命令

啟動(dòng)代碼格式: nginx安裝目錄地址 -c nginx配置文件地址
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

停止

nginx的停止有三種方式:

正常停止

  • 1.查看進(jìn)程號(hào)
    ps -ef|grep nginx
    [root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
    root     24083     1  0 14:22 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    nobody   24084 24083  0 14:22 ?        00:00:00 nginx: worker process
    root     24090 23962  0 14:22 pts/0    00:00:00 grep --color=auto nginx
  • 2.殺掉進(jìn)程
    kill -QUIT 進(jìn)程號(hào)
[root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
root     25427     1  0 17:32 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   25428 25427  0 17:32 ?        00:00:00 nginx: worker process
root     25430 25398  0 17:32 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz ~]# kill -QUIT 25427
[root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
root     25432 25398  0 17:32 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz ~]# 

快速停止

  • 1.查看進(jìn)程號(hào)
    ps -ef|grep nginx

  • 2.殺死進(jìn)程
    kill -TERM 進(jìn)程號(hào)kill -INT 進(jìn)程號(hào)

[root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
root     25434     1  0 17:33 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   25435 25434  0 17:33 ?        00:00:00 nginx: worker process
root     25437 25398  0 17:33 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz ~]# kill -TERM 25434
[root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
root     25443 25398  0 17:34 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz ~]# 

強(qiáng)制停止

kill -9 進(jìn)程號(hào)

[root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
root     24083     1  0 Jan15 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   24084 24083  0 Jan15 ?        00:00:00 nginx: worker process
root     25416 25398  0 17:26 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz ~]#  kill -9 24083
[root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
nobody   24084     1  0 Jan15 ?        00:00:00 nginx: worker process
root     25418 25398  0 17:28 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz ~]#  kill -9 24084
[root@izbp17dek6gh6fp3fctexdz ~]# ps -ef|grep nginx
root     25420 25398  0 17:28 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz ~]# 

重啟

1.驗(yàn)證 nginx 配置文件是否正確

  • 方法一、進(jìn)入 nginx 安裝目錄sbin 下,輸入命令 ./nginx -t
[root@izbp17dek6gh6fp3fctexdz ~]# cd /usr/local/nginx/sbin
[root@izbp17dek6gh6fp3fctexdz sbin]# 
[root@izbp17dek6gh6fp3fctexdz sbin]# 
[root@izbp17dek6gh6fp3fctexdz sbin]# 
[root@izbp17dek6gh6fp3fctexdz sbin]# 
[root@izbp17dek6gh6fp3fctexdz sbin]# 
[root@izbp17dek6gh6fp3fctexdz sbin]# ll
total 3660
-rwxr-xr-x 1 root root 3746656 Nov 26 10:02 nginx
[root@izbp17dek6gh6fp3fctexdz 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
[root@izbp17dek6gh6fp3fctexdz sbin]# 

看到顯示 nginx.conf syntax is oknginx.conf test is successful

說明配置文件正確!

  • 方法二:在啟動(dòng)命令-c前加-t
    /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
[root@izbp17dek6gh6fp3fctexdz 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
[root@izbp17dek6gh6fp3fctexdz sbin]# 

2、重啟Nginx服務(wù)

  • 方法一:進(jìn)入nginx可執(zhí)行目錄sbin下,輸入命令./nginx -s reload 即可
[root@izbp17dek6gh6fp3fctexdz sbin]# cd /usr/local/nginx/sbin
[root@izbp17dek6gh6fp3fctexdz sbin]# ls
nginx
[root@izbp17dek6gh6fp3fctexdz sbin]# ./nginx -s reload
[root@izbp17dek6gh6fp3fctexdz sbin]# ps -ef|grep nginx
root     25445     1  0 17:34 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   25465 25445  0 17:44 ?        00:00:00 nginx: worker process
root     25467 25398  0 17:44 pts/0   
  • 方法二:查找當(dāng)前nginx進(jìn)程號(hào),然后輸入命令:kill -HUP 進(jìn)程號(hào) 實(shí)現(xiàn)重啟nginx服務(wù)
[root@izbp17dek6gh6fp3fctexdz sbin]# ps -ef|grep nginx
root     25445     1  0 17:34 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   25465 25445  0 17:44 ?        00:00:00 nginx: worker process
root     25473 25398  0 17:44 pts/0    00:00:00 grep --color=auto nginx
[root@izbp17dek6gh6fp3fctexdz sbin]# kill -HUP 25445
[root@izbp17dek6gh6fp3fctexdz sbin]# ps -ef|grep nginx
root     25445     1  0 17:34 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   25474 25445  0 17:45 ?        00:00:00 nginx: worker process
root     25476 25398  0 17:45 pts/0    00:00:00 grep --color=auto nginx
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容