[英]PM2 and Nginx: 502 Bad Gateway
I've been trying to deploy my Node project on a brand new DO droplet, but i'm having some problems with PM2.我一直在尝试在全新的 DO droplet 上部署我的 Node 项目,但是我在使用 PM2 时遇到了一些问题。
My steps are a follows:我的步骤如下:
All i get is Nginx complaining about a 502 Bad Gateway.我得到的只是 Nginx 抱怨 502 Bad Gateway。
If i look at the Nginx error.log i get this:如果我查看 Nginx error.log 我得到这个:
connect() failed (111: Connection refused) while connecting to upstream, client: client.ip , server: my.server , request: "GET / HTTP/1.1", upstream: " http://127.0.0.1:3000/ ", host: " my.server "
connect() 连接到上游时失败(111:连接被拒绝),客户端: client.ip ,服务器: my.server ,请求:“GET/HTTP/1.1”,上游:“ http://127.0.0.1:3000/ ", 主机: " my.server "
PM2 doesn't have much to say about anything. PM2 没什么好说的。 Nothing in pm2 logs and status is online .
pm2 日志和状态中没有任何内容处于在线状态。
I tried skipping PM2 and just doing npm start which worked perfectly.我尝试跳过 PM2 并只执行 npm start ,效果很好。 I also tried setting up a dummy hello world application instead, and using that with PM2 - it also worked.
我还尝试设置一个虚拟的 hello world 应用程序,并将其与 PM2 一起使用 - 它也有效。
So this is currently where i'm at:所以这就是我目前所处的位置:
I'm not really sure where to go from here.. I could just skip PM2 and use node, but i do want the features of PM2.我不确定从哪里开始..我可以跳过 PM2 并使用 node,但我确实想要 PM2 的功能。
Any ideas?有什么想法吗?
I just had to start PM2 with bin/www instead of app.js .我只需要用bin/www而不是app.js来启动 PM2。 Express generator and everything...
快递发电机和一切......
Nginx has a directive called proxy_read_timeout which defaults to 60 secs. Nginx 有一个名为 proxy_read_timeout 的指令,默认为 60 秒。 It determines how long nginx will wait to get the response to a request.
它决定了 nginx 将等待多长时间才能获得对请求的响应。 In nginx.
在 Nginx 中。 conf file, setting proxy_read_timeout to 120 secs solved our problem.
conf 文件,将 proxy_read_timeout 设置为 120 秒解决了我们的问题。
It may be a problem with pm2 --watch
argument if you use it.如果您使用
--watch
参数,它可能是一个问题。 It may detect updating logs and keeping restarting server.它可能会检测更新日志并保持重新启动服务器。
This is some issue with the node installation.这是节点安装的一些问题。 Delete the node_modules folder, install again using npm and start the project using pm2.
删除 node_modules 文件夹,再次使用 npm 安装,使用 pm2 启动项目。
pm2 kill下午2杀
rm -rf node_modules rm -rf node_modules
npm i我的
pm2 start bin/www pm2 启动 bin/www
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.