bash 错误:“/run/nginx.pid”中的无效 PID 号“”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36176255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:24:11  来源:igfitidea点击:

ERROR : invalid PID number "" in "/run/nginx.pid"

linuxbashnginx

提问by aksy91

My nginx is not starting on 80 port.

我的 nginx 没有在 80 端口上启动。

I have added the following details:

我添加了以下详细信息:

$ nginx -s reload
2016/03/23 16:11:27 [error] 24992#0: invalid PID number "" in "/run/nginx.pid"
$ ps -ef | grep nginx
root     25057  2840  0 16:16 pts/1    00:00:00 grep --color=auto nginx
$ kill -9 25057
bash: kill: (25057) - No such process
$ service nginx start
Nothing..

Please provide solution..

请提供解决方案..

回答by brujoand

Trying to run nginx -s reloadwithout first starting nginx will result in an error because nginx will look for the file containing it's master pid when you tell it to restart. In your case it seems that nginx wasn't running, so the file containing that id doesn't exist.

尝试在nginx -s reload不首先启动 nginx 的情况下运行将导致错误,因为当您告诉它重新启动时,nginx 将查找包含其主 pid 的文件。在您的情况下,nginx 似乎没有运行,因此包含该 ID 的文件不存在。

By running kill -9 25057you tried to kill your own command ps -ef | grep nginxwhich no longer existed, so you got "No such process".

通过运行,kill -9 25057你试图杀死自己ps -ef | grep nginx不再存在的命令,所以你得到了“没有这样的过程”。

To make sure all is well I would stop nginx with nginx -s stopthen start it with nginxfollowed by nginx -s reloadto check that all is well. In any case the log file might tell you if something bad is going on /var/log/nginx/error.log.

为了确保一切正常,我会停止 nginx,nginx -s stop然后启动它,nginx然后nginx -s reload检查一切是否正常。无论如何,日志文件可能会告诉您是否发生了不好的事情/var/log/nginx/error.log

If that works, you can try accessing http://localhost:80or however you have configured nginx, and also follow the error log, and access log /var/log/nginx/error.log

如果可行,您可以尝试访问http://localhost:80或者您已经配置了 nginx,并按照错误日志和访问日志/var/log/nginx/error.log

As a sidenote: If this by any chance happens to be a case where nginx is reloaded by some other tool like confd, you should also check if nginx actually stores it's pid in /run/nginx.pidas opposed to /var/run/nginx/nginx.pid.

作为一个旁注:如果任何机会恰好是其中nginx的是像confd其他一些工具重载的情况下,您也应该检查是否nginx的实际存储它的PID值/run/nginx.pid,而不是/var/run/nginx/nginx.pid

回答by turkus

Let's talk about what we have here first:

让我们先谈谈我们这里有什么:

$ nginx -s reload
2016/03/23 16:11:27 [error] 24992#0: invalid PID number "" in "/run/nginx.pid"

It's probably because the /run/nginx.pidfile is empty, that causes issues with stop|start|restart commands, so you have to edit it by sudo and put there PID of your current running nginx service (master process). Now, let's have a look at the next lines, which are connected with.

可能是因为/run/nginx.pid文件为空,导致 stop|start|restart 命令出现问题,因此您必须通过 sudo 对其进行编辑,并将当前正在运行的 nginx 服务(主进程)的 PI​​D 放在那里。现在,让我们看看下一行,它们与 .

$ ps -ef | grep nginx
root     25057  2840  0 16:16 pts/1    00:00:00 grep --color=auto nginx
$ kill -9 25057
bash: kill: (25057) - No such process

You're trying here to kill NOT a main process of the nginx. First try to run the following command to see the pids of an nginx master process and his worker:

你在这里试图杀死不是 nginx 的主要进程。首先尝试运行以下命令以查看 nginx 主进程及其工作进程的 pid:

$ ps -aux | grep "nginx"
root     17711  0.0  0.3 126416  6632 ?        Ss   18:29   0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
www-data 17857  0.0  0.2 126732  5588 ?        S    18:32   0:00 nginx: worker process
ubuntu   18264  0.0  0.0  12916   984 pts/0    S+   18:51   0:00 grep --color=auto nginx

Next, kill both:

接下来,杀死两个:

$ sudo kill -9 17711
$ sudo kill -9 17857

and then try to run an nginx again.

然后再次尝试运行 nginx。

$ service nginx start
Nothing..

Have nothing to say here ;)

这里没什么好说的;)

Summary:

概括:

I think editing the /run/nginx.pidfile with an nginx master process PID should solve the issue. So according to my example above, this file should looks like this:

我认为/run/nginx.pid使用 nginx 主进程 PID编辑文件应该可以解决这个问题。所以根据我上面的例子,这个文件应该是这样的:

17711

Hope that helps!

希望有帮助!