gpt4 book ai didi

nginx - 我无法重新启动我的 nginx

转载 作者:行者123 更新时间:2023-12-04 16:44:34 35 4
gpt4 key购买 nike

在控制台显示如下:

Job for nginx.service failed because the control process exited witherror code. See "systemctl status nginx.service" and "journalctl -xe"for details.

我尝试了以下命令:

sudo nginx -t -c/etc/nginx/nginx.conf

sudo nginx -t

它显示成功消息,但 nginx 服务器没有重新启动。

sudo systemctl status nginx.service

nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2018-07-18 18:06:51 IST; 11min ago
Process: 28271 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 28259 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 5236 (code=exited, status=0/SUCCESS)

nginx错误日志有这个错误

bind() to 0.0.0.0:443 failed (98: Address already in use)2018/07/18 18:06:49 [emerg] 28271#28271: bind() to [::]:443 failed (98: Address already in use)2018/07/18 18:06:49 [emerg] 28271#28271: bind() to 0.0.0.0:80 failed (98: Address already in use)

2018/07/18 18:06:49 [emerg] 28271#28271: still could not bind()

最佳答案

尝试运行以下两条命令:

sudo fuser -k 80/tcp

sudo fuser -k 443/tcp

然后执行

sudo service nginx restart

如果可行,您的托管服务提供商可能会在全新安装期间默认在您的服务器上安装 Apache,因此请继续阅读以获得更持久的修复。 如果这不起作用,请继续阅读以找出问题所在。

运行 nginx -t如果它没有返回任何东西,我会验证 Nginx 错误日志。默认情况下,它应该位于 /var/log/nginx/error.log .

您可以使用任何文本编辑器打开它: sudo nano /var/log/nginx/error.log

你能在那里找到可疑的东西吗?

您可以检查的第二个日志如下

sudo nano /var/log/syslog

当我遇到此问题时,是因为我的托管服务提供商在全新安装期间自动安装了 Apache。它阻塞了 80 端口。

当我执行 sudo nano /var/log/nginx/error.log 时我得到以下错误日志:

2018/08/04 06:17:33 [emerg] 634#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/08/04 06:17:33 [emerg] 634#0: bind() to [::]:80 failed (98: Address already in use)
2018/08/04 06:17:33 [emerg] 634#0: bind() to 0.0.0.0:80 failed (98: Address already in use)

上面的错误说明它无法将 nginx 绑定(bind)到端口 80,因为它已经在使用中。

要解决此问题,您需要运行以下命令:

yum install net-tools

sudo netstat -tulpn

当您执行上述操作时,您将得到如下内容:

Proto Recv-Q Send-Q Local Address           Foreign Address         State    PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1762/httpd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1224/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1528/sendmail:acce
tcp6 0 0 :::22 :::* LISTEN 1224/sshd

您可以看到端口 80 被 httpd (Apache) 阻止。如果您使用 SSL,这也可能是端口 443。

获取使用端口 80 或 443 的进程的 PID。并发送 kill 命令更改 <PID>值(value):

sudo kill -2 <PID>

请注意,在我的示例中,Apache 的 PID 值为 1762所以我会执行sudo kill -2 1762

您也可以执行以下操作:

sudo fuser -k 80/tcp

sudo fuser -k 443/tcp

现在 80 或 443 端口已清除,您可以通过运行以下命令启动 Nginx:

sudo service nginx restart

还建议删除以前阻塞端口 80 和 443 的任何内容。这将避免将来发生任何冲突。由于 Apache (httpd) 阻止了我的端口,我通过运行以下命令将其删除:

yum remove httpd httpd-devel httpd-manual httpd-tools mod_auth_kerb mod_auth_mysql mod_auth_pgsql mod_authz_ldap mod_dav_svn mod_dnssd mod_nss mod_perl mod_revocator mod_ssl mod_wsgi

希望这会有所帮助。

关于nginx - 我无法重新启动我的 nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51402373/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com