我想停止Nginx,但是它失败了。
$ sudo service nginx stop Stopping nginx: [FAILED]
而定义nginx.pid的地方的nginx.conf有一行。
# /etc/nginx/nginx.conf pid /var/run/nginx.pid;
但目录/var/run/
没有nginx.pid
。
locate nginx.pid
显示这个输出。
/var/run/nginx.pid /var/run/nginx.pid.oldbin
但更新之后,没有匹配的search。 我在CentOS release 6.5 (Final)
使用了nginx / 1.4.4。
我该怎么做才能阻止nginx守护进程?
这是ps -ef | grep 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
而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]
我会build议停止nginx先杀死它的主进程。 nginx没有正常closures可能是因为它不能用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
再次validation是否有任何nginx进程正在运行或端口80被占用。 如果看到任何进程绑定到端口80,请确定PID并检查是否可以终止。
ps -ef | grep nginx
netstat -tulpn | grep 80
确保文件系统是正常的,你可以读/写到/ var文件系统。 然后启动nginx
服务nginx启动
我有这个问题,并运行ps -ef | grep nginx
ps -ef | grep nginx
会告诉我工作人员将继续旋转起来,尽pipe按照接受的答案build议杀死主进程:
[~]# 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
所以我的解决scheme是简单的: pkill nginx && service nginx restart
对于我来说,这两个文件中的pid文件名是不同的:
pid /var/run/nginx.pid;
PIDFile=/run/nginx.pid
这两个需要匹配。
所以我调整了/usr/lib/systemd/system/nginx.service然后做:
systemctl daemon-reload systemctl start nginx
然后它正确地来了。
我的问题是,我有两个不同的conf文件中指定的pid
。 删除一个引用后,删除.pid
文件,并再次启动nginx它开始正常行为。
这似乎表明,如果nginx已经启动,nginx会立即崩溃。 你检查了/var/log/nginx*
来看看进程在做什么?
编辑:另外,如果你告诉我们你的操作系统和Nginx的版本,我们可以给出更详细的答案。
我需要更多的信息,但是,我猜你已经有另一个 Web服务器运行,而不是你想要自己的ngnix的实例,所以你需要find它 – 错误说,端口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
正确closures其他Web服务器(因为如果它产生的新贵,一个正常的'杀'可能无法正常工作),并尝试启动ngnix。 如果是这样的话,你可以/然后编辑你的init脚本来停止其他web服务器的启动,或者在另一个电源上调整它的configuration。