Ubuntu Nginx守护进程停止失败
我已经安装了带有nginx1.0.11的ubuntu11.04i386服务器。另外,我正在使用,这是我在几个不同的地方发现的唯一一个。但是,在停止/重置时,它会很好地启动服务器Ubuntu Nginx守护进程停止失败,ubuntu,nginx,daemon,init.d,Ubuntu,Nginx,Daemon,Init.d,我已经安装了带有nginx1.0.11的ubuntu11.04i386服务器。另外,我正在使用,这是我在几个不同的地方发现的唯一一个。但是,在停止/重置时,它会很好地启动服务器 * Stopping Nginx Server... [fail] 当然,守护进程不会停止,并且在重新启动时不会重新加载配置 如何修复此问题?我修改了一个nginx init脚本(基于过时版本),它可以与许多基于debian的发行版一起使用,包括Ubuntu 11.04: 这在我的ubuntu服务器上运行得
* Stopping Nginx Server... [fail]
当然,守护进程不会停止,并且在重新启动时不会重新加载配置
如何修复此问题?我修改了一个nginx init脚本(基于过时版本),它可以与许多基于debian的发行版一起使用,包括Ubuntu 11.04:
这在我的ubuntu服务器上运行得很好。希望这有帮助 它很可能无法终止进程 打开位于/etc/init.d/(或/etc/rc.d/)中的nginx sysvinit脚本,找到nginx.pid的位置。它将类似于“/var/run/nginx.pid” 如果pid文件不存在,请打开nginx.conf并查找pid设置。如果不匹配-将conf值设置为脚本认为应该设置的位置,例如
# pid of nginx process
pid /var/run/nginx.pid;
sudo服务nginx restart
将为您提供如下功能:
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()
然后通过其端口手动终止进程:
sudo fuser-k 80/tcp
(或使用您正在使用的任何端口)
或者,按进程ID终止进程:
ps -ef |grep nginx
kill <pid>
ps-ef | grep nginx
杀死
我也遇到过类似的问题
通常我使用apache/apache2
以下内容可能会对您有所帮助:
sudo nginx -s stop | ps -ef | grep nginx | awk {'print $2'} | xargs sudo kill -9 | sudo service apache2 start
有关文档,请参阅此尝试以下命令:
sudo fuser -k 80/tcp
这一问题的原因
- 启动nginx时,它会将pid写入
nginx.conf
- 参考:
- 当您运行
时,它会停止根据服务nginx stop
定义PID的进程(您的路径可能不同)/usr/lib/systemd/system/nginx.service
- 这意味着该进程实际上并未停止李>
- 当您再次尝试启动它时,它会尝试绑定到同一端口并抛出错误
nginx.conf
和nginx.service
中定义的pid文件应该相同
修补程序:
lsof-i|grep nginx
kill-9pid1
kill-9 pid2
(可能不需要)这里有一个我修改过的nginx init脚本(基于官方init脚本),我创建了脚本的变量
lockfile=$pidfile
pidfile="/var/run/nginx.pid"
pid="/var/run/nginx.pid"
变量呢
lockfile=$pidfile
pidfile="/var/run/nginx.pid"
pid="/var/run/nginx.pid"
然后我修改了配置文件(nginx.conf
),使变量
lockfile=$pidfile
pidfile="/var/run/nginx.pid"
pid="/var/run/nginx.pid"
也是
最后,我可以正常使用所有的nginx命令。对我来说,是nginx.conf中的
/run/nginx.pid
替换为/var/run/nginx.pid
,它工作了。谢谢谢谢-我在两个dir中都看到了pid文件,但是将init和nginx.conf更改为指向'var'dir反而解决了我的停止/重新启动脚本中的相同问题。