服务器上的 MEAN 应用程序崩溃

MEAN App on server crashes

我尝试 运行 Nginx 服务器上的 MEAN 应用程序,但它总是在以下时间后崩溃:

// port is 8080
app.listen(port, (data) => {
  console.log('Listening on port ' + port + ' in ' + process.env.NODE_ENV + ' mode');
});

我的防火墙状态是

Status: active
To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere  
Nginx Full                 ALLOW       Anywhere   
8080                       ALLOW       Anywhere  
OpenSSH (v6)               ALLOW       Anywhere (v6) 
Nginx Full (v6)            ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6)  

错误

listen EADDRINUSE :::8080

我已经使用 this tutorial 设置了服务器。

似乎 8080 已在使用中,但我如何找出它的用途并修复它?

要尝试获取正在侦听端口的进程,请输入:

sudo netstat -tulpn | grep :8080

这应该能告诉您正在使用该端口的内容。

然后通过 PID 终止进程,只需使用

sudo kill pid

来自 https://www.cyberciti.biz/faq/what-process-has-open-linux-port/

另一种方法是使用 sudo fuser -k 8080/tcp 直接终止 TCP 端口 8080 上的进程。

既然你提到你遵循了教程

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

这表明您 运行 PM2 正在重新启动节点,即使您杀死了它。所以你需要停止PM2

sudo pkill PM2

然后你就可以正常启动你的node程序了