nginx服务的启动 停止和重启

nginx 命令

启动 nginx 命令

启动代码格式: nginx安装目录地址 -c nginx配置文件地址
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

停止

nginx的停止有三种方式:

正常停止

  • 1.查看进程号
    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.杀掉进程
    kill -QUIT 进程号
[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.查看进程号
    ps -ef|grep nginx

  • 2.杀死进程
    kill -TERM 进程号kill -INT 进程号

[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 ~]# 

强制停止

kill -9 进程号

[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.验证 nginx 配置文件是否正确

  • 方法一、进入 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

说明配置文件正确!

  • 方法二:在启动命令-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服务

  • 方法一:进入nginx可执行目录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   
  • 方法二:查找当前nginx进程号,然后输入命令:kill -HUP 进程号 实现重启nginx服务
[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

你可能感兴趣的:(nginx服务的启动 停止和重启)