Nginx 配置无法重新加载。出现“bind() to 0.0.0.0:80 failed (98: Address already in use)”错误

Nginx 配置无法重新加载。出现“bind() to 0.0.0.0:80 failed (98: Address already in use)”错误

我尝试安装 HTTPS 证书,经过几个小时的苦思冥想,我意识到 Nginx 并没有接收我在网站配置文件中所做的更改。/etc/nginx/sites-available/

当我运行它时,service nginx restart它重新启动正常。当我运行nginx -t它时,它说我的语法正确,我的配置测试成功。然而,当我运行它时,service nginx reload我收到一条错误消息,说reload: Not running

当我查看时,/var/log/nginx/error.log发现了这些错误。

2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to 0.0.0.0:443 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: bind() to [::]:80 failed (98: Address already in use)
2016/08/29 16:04:40 [emerg] 14744#14744: still could not bind()

在 Google 上搜索后,我偶然发现了这个命令netstat -plutn | grep 80,它给了我...

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      14642/nginx: worker
tcp6       0      0 :::80                   :::*                    LISTEN      14642/nginx: worker

我不知道这到底是什么意思,但读了一番,似乎 Nginx 不应该在端口 80 上运行?Nginx 是我的 Web 服务器,难道我不希望它在端口 80 上运行吗?

不确定如何继续。我希望 Nginx 能够获取我使用该service nginx reload命令在站点配置文件中所做的更改,同时我犹豫是否只是复制/粘贴我在网上找到的命令,因为我在这个服务器上托管了 10 个网站。

我哪里做错了?我尝试按照某些人的建议删除文件夹default中的文件sites-available,但我真的不明白问题是什么,也不知道如何解决。

答案1

问题已解决。正如 Tim 所说,我运行了命令ps -ef | grep nginx并手动运行kill PID了所有进程。然后我运行了service nginx restart,一切正常。当我运行时,service nginx reload我没有收到错误,我的 HTTPS 证书现在有效。感谢 Tim 和 dmourati 的帮助

答案2

听起来你的 init 脚本和 nginx 的 pid 文件位置有问题。你可以手动终止 nginx,如下所示:

sudo kill 14642

然后通过 init 脚本启动 nginx,如下所示:

sudo 服务 nginx 启动

从那里,如果你复制/粘贴你的初始化脚本和 nginx.conf 文件,我相信我们可以找到 pid 的问题。

相关内容