我们有一个使用pm2 Process Manager在端口3000上运行的Express应用程序。我们正在使用nginx将请求反向代理到节点应用程序。但是突然之间,nginx停止了自己的运行。它发生在几天前,我们重新启动后就可以了。但是今天,它再次失败了。当时我们检查nginx status
会给出此输出,
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 Sat 2018-09-22 12:38:52 UTC; 1h 43min ago
Process: 21571 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCES
Process: 21680 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 21676 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 8027 (code=exited, status=0/SUCCESS)
Sep 22 12:38:51 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 22 12:38:51 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 22 12:38:52 ip-172-31-27-16 nginx[21680]: nginx: [emerg] still could not bind()
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: nginx.service: Control process exited, code=exited status=1
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: nginx.service: Unit entered failed state.
Sep 22 12:38:52 ip-172-31-27-16 systemd[1]: nginx.service: Failed with result 'exit-code'.
这是nginx error.log
2018/09/22 12:38:41 [warn] 21539#21539: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:48 [warn] 21641#21641: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:48 [notice] 21641#21641: signal process started
2018/09/22 12:38:48 [error] 21641#21641: open() "/run/nginx.pid" failed (2: No such file or directory)
2018/09/22 12:38:48 [warn] 21642#21642: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:50 [warn] 21676#21676: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:50 [warn] 21680#21680: conflicting server name "example.com" on 0.0.0.0:80, ignored
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:443 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to 0.0.0.0:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: bind() to [::]:80 failed (98: Address already in use)
2018/09/22 12:38:50 [emerg] 21680#21680: still could not bind()
2018/09/22 12:38:52 [alert] 21643#21643: unlink() "/run/nginx.pid" failed (2: No such file or directory)
知道为什么会这样吗?我们的Nginx配置有问题,或者我们的节点应用程序以某种方式引起了麻烦?
答案 0 :(得分:0)
每个日志似乎都已经在使用端口80和443。可能是任何东西。同样在少数情况下,它可能是nginx本身。然后我建议重启服务器。
我将通过以下方式开始指出实际使用这些端口的位置:
# netstat -tulpn | grep :80
# netstat -tulpn | grep :443
然后将检查nginx
错误日志以了解更多信息
tail -n 500 /var/log/nginx/error.log
然后,如果您使用这些端口找到其他应用,则可以检查它们是什么:
# whatis <appName>
# whereis <appName>
如果是由其他应用引起的,则可以将其关闭或重新绑定到另一个端口。
希望它会有所帮助:)