nginx 配置文件 ok reload 报错

pkill nginx && service nginx restart
QA Stack
服务器管理员
Tags
Account
Nginx无法停止并且缺少nginx.pid
33
我想停止Nginx,但是这样失败了。

$ sudo service nginx stop
Stopping nginx: [FAILED]
并且nginx.conf定义了nginx.pid的位置有一行。

/etc/nginx/nginx.conf

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

locate nginx.pid 显示此输出。

/var/run/nginx.pid
/var/run/nginx.pid.oldbin
但是之后updatedb没有匹配的搜索。我在中使用nginx / 1.4.4 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
并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]
centos nginx
— 铁砂
source

3
如果nginx没有运行,则系统无法停止它,并且由于没有PID文件,我怀疑它已经停止了。您可以使用ps -ef | grep nginx或进行检查sudo netstat -tlnp | grep nginx。
— Ladadadada 2014年
1
谢谢你的建议。我添加了ps命令结果。
— ironsand 2014年
Answers:

37
我建议先通过杀死它的主进程来停止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启动

— 桑迪普
source
谢谢!杀死主进程后,我还必须杀死nginx worker进程。然后,我终于可以启动nginx守护程序了。
— ironsand 2014年
您刚刚拯救了灵魂Sandeep!非常感谢用于记录…
— 塞尔
谢谢@ sandeep.s85。对我也有用。出于兴趣,什么会导致nginx运行时缺少nginx.pid文件?
— Codemonkey
对我来说,这再次发生了,我希望我知道是什么原因造成的。
— Codemonkey
我杀死了Nginx主进程后,它又恢复了正常运行。
— WTIFS
11
问题
对我来说,两个文件中的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
然后它正确地出现了。

— 帕特里克·布斯
source
3
怎么来的?在Ubuntu中,/var/run/是/run/
— Z. Zlatev
是的,所以这根本不是解决方案。但就我而言,一切都是/run/nginx.pid。
— 危险89年
我的nginx.conf中包含pid logs / nginx.pid-更改为/run/nginx.pid并已修复,谢谢Patrick!
— phpguru
9
我遇到了这个问题,奔跑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
所以我的解决方案就是:pkill nginx && service nginx restart

— 阿穆雷尔
source
1
我的问题是我pid在两个不同的conf文件中指定了。在我删除一个参考然后删除.pid文件并再次启动nginx之后,它开始正常运行。

— 马修·丹尼尔
source
是的,PID是在/usr/lib/systemd/system/nginx-debug.service和/etc/nginx/nginx.conf中定义的
— edmondscommerce
0
这似乎表明nginx立即崩溃了,如果它早已启动的话。您是否已检查的内容/var/log/nginx*以查看该流程在做什么?

编辑:另外,如果您告诉我们您的操作系统和Nginx版本,我们可以给出更详细的答案。

— 日汉
source
0
我需要更多信息以确保,但是,我猜测您已经在运行另一个 Web服务器,而不是您想要的ngnix实例,因此您需要找到它-错误表明端口80正在使用,但不是什么

尝试netstat -tulpn-您正在本地地址下寻找一个以:80结尾的条目-这还将为您提供程序名称和PID,以便您可以识别它。这是我的-我正在运行lighttpd,其显示在第三行。

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 4684/rtorrent
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 923/php-fpm.conf)
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 972/lighttpd
tcp 0 0 0.0.0.0:6901 0.0.0.0:* LISTEN 4684/rtorrent
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 720/sshd
tcp6 0 0 :::22 ::😗 LISTEN 720/sshd
udp 0 0 0.0.0.0:6881 0.0.0.0:* 4684/rtorrent
正确关闭其他Web服务器(因为如果它是由新贵产生的,则可能无法正常执行“杀死”操作),然后尝试启动ngnix。如果是这样,您可以/应该然后编辑您的初始化脚本以停止其他Web服务器的启动,或者通过其他电源调整其配置。

— 游侠怪胎
source
谢谢你的帮助。netstat -tulpn显示tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19507/nginx。因此,nginx以某种方式占用了该端口。但是正如sandeep所说,我杀死了nginx进程,然后它起作用了。我感谢您的帮助!
— ironsand 2014年
0
我对Ubuntu 10.10和在/ opt / nginx / sbin中运行的nginx的编译版本有类似的问题。

检查/opt/nginx/conf/nginx.conf和/etc/nginx/nginx.conf文件,并验证它们是否匹配。

使用以下命令调整/etc/init.d/nginx启动文件以匹配nginx.pid位置测试:

sudo /etc/init.d/nginx configtest # should show no failures
sudo /etc/init.d/nginx start # should show starting
sudo /etc/init.d/nginx status # should show running
sudo /etc/init.d/nginx stop # should show stopping – (wait for a few)
sudo /etc/init.d/nginx status # should show can not access PID file for nginx
sudo netstat -tap # should not show nginx program running with open local address
— 皮特·威廉姆斯
source
0
要停止nginx,请查看手册中的操作方法man nginx。

默认方式应该是将停止信号与配合使用nginx -s stop。

真的应该那么简单。您的选择是:

stop, quit, reopen, reload.
— 普罗斯蒂
source
Similar questions:
cron.daily什么时候运行? 199
如何在CentOS上安装Node.JS? 131
CentOS与Ubuntu 104
如何从RHEL / CentOS Shell验证远程Web服务器上是否支持TLS 1.2? 102
如何从权威的时间服务器更新CentOS服务器的时间? 99

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值