当以下任何命令出现权限问题时,首先查看是否拥有权限,再次查看是否加上sudo
1.查看nginx路径
nginx的配置放在nginx.conf文件中,一般我们可以使用以下命令查看服务器中存在的nginx.conf文件。
[root@ITRI-IoTPlatform-Test ~]# locate nginx.conf
/usr/local/etc/nginx/nginx.conf
/usr/local/etc/nginx/nginx.conf.default
如果服务器中存在多个nginx.conf文件,我们并不知道实际上调用的是哪个配置文件,因此我们必须找到实际调用的配置文件才能进行修改
[root@ITRI-IoTPlatform-Test ~]# ps aux|grep nginx
root 352 0.0 0.0 2468624 924 ?? S 10:43上午 0:00.08 nginx: worker process
root 232 0.0 0.0 2459408 532 ?? S 10:43上午 0:00.02 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
root 2345 0.0 0.0 2432772 640 s000 S+ 1:01下午 0:00.00 grep nginx
nginx的路径为:/usr/local/opt/nginx/bin/nginx
2.Nginx强制关闭
root@hecs02:/etc/nginx# pkill -9 nginx
3.Nginx重启
(1)、一般重启
i、查看Nginx master进程号
root@hecs02:/etc/nginx# ps -ef|grep nginx
(2)、修改配置文件后重启
i、查看修改的配置文件是否有误,前提Nginx必须开启状态
root@hecs02:/usr/sbin# ./nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
ii、确认修改没有问题后,重启Nginx
# 指定配置文件
root@hecs02:/usr/sbin# ./nginx -c /etc/nginx/nginx.conf
# 重启
root@hecs02:/usr/sbin# ./nginx -s reload
定位后Nginx可执行程序,然后输入 -s reload,完成重启,该重启不需要关闭Nginx服务器.