[错误]|nginx: [error] invalid PID number "" in "/usr/local/nginx-1.12.2/nginx_my.pid"

本文介绍了一个常见的nginx启动问题,即尝试使用reload命令启动已停止的nginx服务时出现的PID错误,并给出了详细的解决步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nginx: [error] invalid PID number “” in “/usr/local/nginx-1.12.2/nginx_my.pid”

nginx: [error] invalid PID number “” in “/usr/local/nginx-1.12.2/nginx_my.pid”
翻译:nginx:[错误]无效的PID编号 “” 在 “/usr/local/nginx-1.12.2/nginxmy.PID”中。
即:在这个文件中PIID编号空字符串

what?:场景再现

停止(stop)了nginx服务,然后自己照着nginx.conf文件,自己写了一个nginx-my.conf文件。接着我就测试我的文件nginx-my.conf 正确性,在用我写的配置文件nginx-my.conf重启(reload) nginx。结果就报这个错误。

好,那我们来分析一下它为什么会发生呢?

why?:什么原因

在nginx处于stop状态时,我用了reload来启动nginx。
注意 : nginx -s reload仅用于告诉正在运行的nginx进程重新加载其配置。在停止之后,您没有正在运行的nginx进程向其发送信号。 所以会报错。

那我就来验证一下我的想法。
来看一下,我们可以先查询一下nginx的进程 是否真的已经启动?

[root@wcl nginx]# ps -ef |grep nginx
 root      8837  8132  0 10:12 pts/0    00:00:00 grep --color=auto nginx     

可以从上面这段指令看出:我没有nginx启动,即nginx现在处于停止(stop)状态。

How?:如何解决

先启动nginx 才能用reload
指令:./sbin/nginx -c conf/nginx-my.conf 启动nginx

需要先启动nginx 才能用reload

[root@wcl nginx]#  ./sbin/nginx  -c conf/nginx-my.conf    //  首次启动nginx
[root@wcl nginx]# ps -ef |grep nginx      //  查看进程nginx  确实能查到 说明 启动成功
root      8840     1  0 10:12 ?        00:00:00 nginx: master process ./sbin/nginx -c conf/
nginx-my.conf
root      8841  8840  0 10:12 ?        00:00:00 nginx: worker process
root      8842  8840  0 10:12 ?        00:00:00 nginx: worker process
root      8843  8840  0 10:12 ?        00:00:00 nginx: worker process
root      8844  8840  0 10:12 ?        00:00:00 nginx: worker process
root      8846  8132  0 10:12 pts/0    00:00:00 grep --color=auto nginx
[root@wcl nginx]# ./sbin/nginx -s reload -c conf/nginx-my.conf // 这时候 我们才能重新启动nginx

总结:nginx -s reload仅用于告诉正在运行的nginx进程重新加载其配置。在停止之后,您没有正在运行的nginx进程向其发送信号,所以才会出错,找不到这个nginx_my.pid中的PID。只需运行nginx(nginx -c / path / to / config /文件) ,才会产生进程号PID.

在这个错误信息中,"nginx: [error] invalid PID number "/usr/local/nginx/logs/nginx.pid"",它是由于nginx在加载配置文件时遇到了无效的进程ID号。而具体原因是由于nginx在重新读取配置文件时,检测到指定的进程ID文件"/usr/local/nginx/logs/nginx.pid"无效或不存在。解决方法是检查"/usr/local/nginx/logs/nginx.pid"文件是否存在,如果不存在,则需要手动指定nginx配置文件的路径来启动nginx,即使用命令"/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf"。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [nginx: [error] invalid PID numberin /usr/local/nginx/logs/nginx.pid](https://blog.csdn.net/qq_25288617/article/details/124607984)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [解决 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid](https://blog.csdn.net/cxs123678/article/details/80201412)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值