简体   繁体   中英

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.

My steps are a follows:

  1. Node came installed on the Droplet image (Ubuntu, Node v4.4.4)
  2. Installed PM2 globally
  3. Setup Nginx to reverse proxy 127.0.0.1:3000
  4. Cloned my project and did npm install

All i get is Nginx complaining about a 502 Bad Gateway.

If i look at the Nginx error.log i get this:

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 "

PM2 doesn't have much to say about anything. Nothing in pm2 logs and status is online .

I tried skipping PM2 and just doing npm start which worked perfectly. I also tried setting up a dummy hello world application instead, and using that with PM2 - it also worked.

So this is currently where i'm at:

  • My project + PM2: doesn't work.
  • My project without PM2: works.
  • Hello World app + PM2: works.

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.

Any ideas?

I just had to start PM2 with bin/www instead of app.js . Express generator and everything...

Nginx has a directive called proxy_read_timeout which defaults to 60 secs. It determines how long nginx will wait to get the response to a request. In nginx. conf file, setting proxy_read_timeout to 120 secs solved our problem.

It may be a problem with pm2 --watch argument if you use it. 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.

pm2 kill

rm -rf node_modules

npm i

pm2 start bin/www

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM