Nginx的启动、停止和重启

启动

启动代码格式: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

posted @ 2019-03-22 17:32  四季镇  阅读(1608)  评论(0编辑  收藏  举报