Nginx服务重启失败:Job for nginx.service failed
作者:佚名
来源:本站原创
点击数: 次
发布时间:2023年11月10日
问题分析:
启动nginx服务提示Nginx服务重启失败,如下提示:
Job for nginx.service failed because the control process exited with error code. Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journal
问题处理:
首先用命令
命令去校验你的Nginx配置是否成功:
nginx -t
如果成功,他会给出如下信息:
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
如果你的配置文件有问题,也能从错误信息中看出来:
duplicate default server for [::]:80 in /etc/nginx/nginx.conf:41
错误已经很明显了,有多个配置文件里面使用了80端口。所以你可以用下面这条命令去查找一下:
grep -R default_server /etc/nginx
# 啰嗦一句,-R的意思是递归查找。这条命令会从 /etc/nginx下递归查找所有包含 default_server 的文件
找到该文件,写个别的端口或者删掉没用的文件,这个错误就可以解决了!
查看Nginx服务状态你可以发现:
# systemctl status nginx.service ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since 2018-11-06 12:31:21 JST; 15s ago ... 11月 06 12:31:20 zhangch-101 nginx[1863]: nginx: [emerg] bind() to 0.0.0.0:5001 failed (98: Address already in use) 11月 06 12:31:21 zhangch-101 systemd[1]: nginx.service: control process exited, code=exited status=1 11月 06 12:31:21 zhangch-101 nginx[1863]: nginx: [emerg] still could not bind() 11月 06 12:31:21 zhangch-101 systemd[1]: Failed to start The nginx HTTP and reverse proxy server. 11月 06 12:31:21 zhangch-101 systemd[1]: Unit nginx.service entered failed state. 11月 06 12:31:21 zhangch-101 systemd[1]: nginx.service failed.
这个错误比较明显,已经有进程占用这个端口了。
这时你就应该去看看哪个进程占用了这个端口:
netstat -nap | grep 5001
原文链接:https://blog.csdn.net/njnujuly/article/details/83821354