一、启动/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
启动代码格式:nginx安装目录地址 -c nginx配置文件地址
例如:
[root@localhost ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
二、停止
nginx的停止有三种方式:
1、从容停止
(1)查看进程号: ps -ef|
grep
nginx
[root@localhost ~]# ps -ef|grep nginx
![](https://img-blog.csdnimg.cn/img_convert/511fabd1dde5c7f469a6af6209df93b5.png)
(2)杀死进程: kill -quit xxxx
142804是进程的编号
[root@localhost ~]# kill -quit 142804
![](https://img-blog.csdnimg.cn/img_convert/bec8df31a9643cd7ced031459dd2295b.png)
2、快速停止
(1)查看进程号: ps -ef|grep nginx
[root@localhost ~]# ps -ef|grep nginx
![](https://img-blog.csdnimg.cn/img_convert/0cbdaf0c324520bd0e957b355b317f96.png)
(2)杀死进程: kill -term xxxx/ kill -int xxxx
142804是进程的编号
[root@localhost ~]# kill -term 142804
或
[root@localhost ~]# kill -int 142804
![](https://img-blog.csdnimg.cn/img_convert/1f80d5aed71f99f248cd4419f4ed4c3c.png)
3、强制停止: pkill -9 nginx
[root@localhost ~]# pkill -9 nginx
三、重启
1、验证nginx配置文件是否正确
(1)方法一:进入nginx安装目录sbin下,输入命令./nginx -t
看到如下显示nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确!
[root@localhost ~]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx -t
![](https://img-blog.csdnimg.cn/img_convert/bf05e04c8db7e5cfcef0456296d73dbc.png)
(2)方法二:在启动命令-c前加-t
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
![](https://img-blog.csdnimg.cn/img_convert/4f3d6a924330dca77eda6b7c17298dfb.png)
2、重启nginx服务
(1)方法一:进入nginx安装目录sbin下,输入命令./nginx -s reload 即可
[root@localhost ~]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx -s reload
![](https://img-blog.csdnimg.cn/img_convert/91e4e4cbdd9c7d4b2e800c564bcf41c5.png)
-
-
方法二:查找当前nginx进程号,然后输入命令:kill -HUP 进程号 实现重启nginx服务
-
![](https://img-blog.csdnimg.cn/img_convert/257c1bd8ec53be7982805cf93ada6acf.png)