Nginx 无法停止并且缺少 nginx.pid

iro*_*and 43 nginx centos

我想停止 Nginx 但它像这样失败了。

$ sudo service nginx stop
Stopping nginx:                                            [FAILED]
Run Code Online (Sandbox Code Playgroud)

nginx.conf定义的地方nginx.pid有一条线。

# /etc/nginx/nginx.conf
pid        /var/run/nginx.pid;
Run Code Online (Sandbox Code Playgroud)

但是nginx.pid目录中没有/var/run/

locate nginx.pid 显示此输出。

/var/run/nginx.pid 
/var/run/nginx.pid.oldbin
Run Code Online (Sandbox Code Playgroud)

但是搜索后updatedb没有匹配项。我在CentOS release 6.5 (Final).

我应该怎么做才能停止 nginx 守护进程?

编辑 2014/01/07

这是 的输出ps -ef | grep nginx,似乎 nginx 守护进程仍在运行。

ironsand 17065 16933  0 15:55 pts/0    00:00:00 grep --color nginx
root     19506     1  0  2013 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
ironsand 19507 19506  0  2013 ?        00:00:25 nginx: worker process  
Run Code Online (Sandbox Code Playgroud)

sudo service nginx restart给出了这个错误。我认为nginx无法开始,因为旧的还活着。并且/var/log/nginx/error.log-2014017还包含此错误。

Stopping nginx:                                            [FAILED]
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
                                                           [FAILED]
Run Code Online (Sandbox Code Playgroud)

san*_*s85 47

我会建议先杀死它的主进程来停止 nginx。nginx 没有正确关闭可能是因为它无法使用 init 脚本停止。

ps -ef |grep nginx

这将向您显示 nginx 主进程的 PID。就像你上面提到的:

根 19506 1 0 2013 年?00:00:00 nginx:主进程/usr/sbin/nginx -c /etc/nginx/nginx.conf

杀死它使用

杀死 -9 19506

再次验证是否有任何nginx进程正在运行或80端口是否被占用。如果您看到任何进程绑定到端口 80,请识别 PID 并检查它是否可以被杀死。

ps -ef |grep nginx

netstat -tulpn |grep 80

确保文件系统正常并且您可以读/写 /var 文件系统。然后启动nginx

服务 nginx 启动

  • 你刚才救了一个灵魂桑迪普!非常感谢记录.. (2认同)

小智 12

问题

对我来说,这两个文件中的 pid 文件名不同:

  • /usr/lib/systemd/system/nginx.service
    • pid /var/run/nginx.pid;
  • /etc/nginx/nginx.conf
    • PIDFile=/run/nginx.pid

这两个需要匹配。

使固定:

所以我在 /usr/lib/systemd/system/nginx.service 中进行了调整,然后做了:

systemctl daemon-reload
systemctl start nginx
Run Code Online (Sandbox Code Playgroud)

然后它正确地出现了。

  • 怎么来的?在 Ubuntu 中,`/var/run/` 是 `/run/` 的符号链接 (3认同)

amu*_*ell 10

我遇到了这个问题,ps -ef | grep nginx尽管按照公认的答案的建议杀死了主进程,但运行会向我显示工作人员会继续旋转:

[~]# ps -ef | grep nginx
nginx    10730     1  0 Sep14 ?        00:00:16 nginx: cache manager process            
nginx    18469     1  0 Oct09 ?        00:11:02 nginx: worker process                   
nginx    25779     1  0 Oct13 ?        00:01:31 nginx: worker process                   
nginx    26458     1  0 15:45 ?        00:00:00 nginx: worker process    
Run Code Online (Sandbox Code Playgroud)

所以修复它的解决方案很简单:pkill nginx && service nginx restart