我想停止 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 守护进程?
这是 的输出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 启动
小智 12
对我来说,这两个文件中的 pid 文件名不同:
pid /var/run/nginx.pid;PIDFile=/run/nginx.pid这两个需要匹配。
所以我在 /usr/lib/systemd/system/nginx.service 中进行了调整,然后做了:
systemctl daemon-reload
systemctl start nginx
Run Code Online (Sandbox Code Playgroud)
然后它正确地出现了。
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
| 归档时间: |
|
| 查看次数: |
153210 次 |
| 最近记录: |