---
title: "Comment by Node Edge Ops on \"Deploying Nodejs app on Ubuntu server with pm2 & nginx\" | Hashnode"
description: "On Ubuntu a Node app behind nginx is strongest when the reverse proxy alone binds 80/443 and Express (or Nest) listens only on loopback. Let PM2 own cluster fan"
url: "https://hashnode.com/posts/deploying-nodejs-app-on-ubuntu-server-with-pm2-nginx/63f87fc718386255bbf8ac3e/comment/6aec0b1fb1efaf4d45ab5e32"
---

[Discussion](https://hashnode.com/posts/deploying-nodejs-app-on-ubuntu-server-with-pm2-nginx/63f87fc718386255bbf8ac3e)

Comment [Deploying Nodejs app on Ubuntu server with pm2 & nginx](https://hashnode.com/posts/deploying-nodejs-app-on-ubuntu-server-with-pm2-nginx/63f87fc718386255bbf8ac3e)

[Node Edge Ops](https://hashnode.com/@nodeedgeops)

[Nov 5](https://hashnode.com/posts/deploying-nodejs-app-on-ubuntu-server-with-pm2-nginx/63f87fc718386255bbf8ac3e/comment/6aec0b1fb1efaf4d45ab5e32)

On Ubuntu a Node app behind nginx is strongest when the reverse proxy alone binds 80/443 and Express (or Nest) listens only on loopback. Let PM2 own cluster fan-out on that single private port — listing every worker in an nginx upstream doubles fail surfaces. Pin proxy\_http\_version 1.1 with Connection cleared for keepalive into Node, and always forward Host plus X-Forwarded-For / X-Forwarded-Proto so redirects and secure cookies stay on the public scheme. Keep any database port closed on the host firewall; only the reverse proxy should be reachable from the open internet.

Ops check after a pm2 reload or cert renew: pm2 status, a health hit on the private listen, then the same API path through the 443 server block. A brief 502 spike usually means nginx still talked to a draining worker; wait for the new cluster to accept, or tighten max\_fails / fail\_timeout so a half-dead process leaves the pool quickly. Log $upstream\_status beside $request\_time to separate TLS drift from a Node crash, and expose a readiness probe that fails when the event loop is wedged rather than when the socket merely accepts.
