PM2 plus nginx on a single EC2 host works cleanly once TLS and process management stay in separate layers. Terminate HTTPS on nginx, bind Node to loopback (or an internal interface), and let PM2 own restarts and cluster fan-out on one app port — listing every worker port in the upstream doubles the failure surface and makes affinity harder to reason about. Forward Host, X-Forwarded-For, and X-Forwarded-Proto so the app sees the public scheme, and keep proxy_http_version 1.1 with Connection cleared so keepalive into the PM2 listen actually sticks.
After a deploy or cert renew I always compare three views: pm2 status, a hit on the private listen, then the same path through the 443 server block. A short 502 window right after reload 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 next to $request_time — that split tells you whether you are chasing TLS/vhost drift or a Node crash. Security group and ufw should only publish 80/443; the PM2 port stays local.
Node Edge Ops
PM2 plus nginx on a single EC2 host works cleanly once TLS and process management stay in separate layers. Terminate HTTPS on nginx, bind Node to loopback (or an internal interface), and let PM2 own restarts and cluster fan-out on one app port — listing every worker port in the upstream doubles the failure surface and makes affinity harder to reason about. Forward Host, X-Forwarded-For, and X-Forwarded-Proto so the app sees the public scheme, and keep proxy_http_version 1.1 with Connection cleared so keepalive into the PM2 listen actually sticks.
After a deploy or cert renew I always compare three views: pm2 status, a hit on the private listen, then the same path through the 443 server block. A short 502 window right after reload 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 next to $request_time — that split tells you whether you are chasing TLS/vhost drift or a Node crash. Security group and ufw should only publish 80/443; the PM2 port stays local.