手把手解决Nginx错误:nginx: [error] invalid PID number ““ in “/run/nginx.pid“

一、错误场景

使用nginx -s reload 重新加载nginx配置报错,或者启动nginx 报错


二、报错信息

错误提示如下:

[root@nues ~]# nginx -s reload
nginx: [error] invalid PID number "" in "/run/nginx.pid"
或者
[root@nues ~]# nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx/nginx.pid

三、报错分析

错误分析:
google一下
nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don’t have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)

翻译过来:
Nginx -s reload只用于告诉正在运行的Nginx进程重新加载它的配置。在停止之后,你没有一个正在运行的nginx进程来发送信号。只需要运行nginx(可能带有-c /path/to/config/文件)

参考资料:https://stackoverflow.com/questions/7646972/nginx-invalid-pid-number


四、处理方法

处理方法1:
重新加载配置文件 nginx.conf,然后再执行 reload

[root@nues ~]# nginx -t  检查Nginx配置是否正确,查到配置路径
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@nues ~]# nginx -c /usr/local/nginx/conf/nginx.conf
[root@nues ~]# nginx -s reload  #还不行使用下面第二种方法

处理方法2:
查询nginx的pid 直接写入到 /run/nginx.pid里面

[root@nues ~]#ps -aux | grep "nginx: master process nginx"
root      2716  0.0  0.0  54348  7636 ?        Ss   Jul03   0:00 nginx: master process nginx
root     24294  0.0  0.0  13144  1084 pts/1    S+   10:00   0:00 grep --color=auto nginx: master process nginx
[root@nues ~]# echo 2716 > /run/nginx.pid
[root@nues ~]# nginx -s reload

处理方法3(慎用):

[root@nues ~]# killall nginx 杀掉所有Nginx进程,生产环境,慎用
[root@nues ~]# nginx
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值