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 nginx2.殺死進(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 ok 和 nginx.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