三种方法解决Nginx错误:nginx: [error] invalid PID number “” in “/run/nginx.pid”
网上的解决方法比较零散且重复。
所以收集了一下,方便以后查阅使用。
一、问题描述
对
nginx
执行
reload
命令时报错:
[MyHome@MyMachine ~]$ sudo nginx -s reload
nginx: [error] invalid PID number "" in "/run/nginx.pid"
二、解决方法
2.1. 方法1:
-
重新加载
配置文件
nginx.conf
,然后再执行
reload
[MyHome@MyMachine ~]$ # nginx.conf 可能不在 /etc/nginx/ 下,具体视 nginx 的安装路径而定
[MyHome@MyMachine ~]$ sudo nginx -c /etc/nginx/nginx.conf
[MyHome@MyMachine ~]$ sudo nginx -s reload
较常用
2.2. 方法2:
-
直接将
nginx
主进程的
PID
写入
"/run/nginx.pid"
[MyHome@MyMachine ~]$ # 下面的命令得到 nginx 主进程的PID:19386
[MyHome@MyMachine ~]$ ps -aux | grep "nginx: master process"
root 19386 0.0 0.0 70060 7308 ? Ss 15:36 0:00 nginx: master process nginx
myname 20740 0.0 0.0 116800 1048 pts/0 S+ 23:31 0:00 grep --color=auto nginx: master process
[MyHome@MyMachine ~]$ sudo echo 19386 > /run/nginx.pid
[MyHome@MyMachine ~]$ sudo nginx -s reload
如果方法1失败了,可以考虑用
2.3. 方法3:
-
杀掉
nginx
的主进程,然后
重启
nginx
[MyHome@MyMachine ~]$ sudo killall nginx
[MyHome@MyMachine ~]$ sudo nginx
最好别用,因为 nginx 会关闭一段时间,重启时也可能节外生枝,这可能影响到服务的使用。
版权声明:本文为qq_29695701原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。