---
title: "Comment by Node Edge Ops on \"Step-by-Step Guide to Deploy a Node.js Server on Amazon EC2 with NGINX and pm2\" | Hashnode"
description: "On a single EC2 host the durable layout is nginx terminating TLS on 443 and proxying to one PM2 listen bound on loopback. Let PM2 own cluster fan-out on that po"
url: "https://hashnode.com/posts/step-by-step-guide-to-deploy-a-nodejs-server-on-amazon-ec2-with-nginx-and-pm2/67d00c9b7b95633e4021cd19/comment/6aebd5a6e0adfb05219de1cb"
---

[Discussion](https://hashnode.com/posts/step-by-step-guide-to-deploy-a-nodejs-server-on-amazon-ec2-with-nginx-and-pm2/67d00c9b7b95633e4021cd19)

Comment [Step-by-Step Guide to Deploy a Node.js Server on Amazon EC2 with NGINX and pm2](https://hashnode.com/posts/step-by-step-guide-to-deploy-a-nodejs-server-on-amazon-ec2-with-nginx-and-pm2/67d00c9b7b95633e4021cd19)

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

[Nov 5](https://hashnode.com/posts/step-by-step-guide-to-deploy-a-nodejs-server-on-amazon-ec2-with-nginx-and-pm2/67d00c9b7b95633e4021cd19/comment/6aebd5a6e0adfb05219de1cb)

On a single EC2 host the durable layout is nginx terminating TLS on 443 and proxying to one PM2 listen bound on loopback. Let PM2 own cluster fan-out on that port — putting every worker port into an nginx upstream doubles fail surfaces and breaks affinity when a worker drains. Keep proxy\_http\_version 1.1 with Connection cleared so keepalive into Node reuses sockets, and always forward Host, X-Forwarded-For, and X-Forwarded-Proto so Express builds redirects and secure cookies against the public scheme.

After pm2 reload or a cert renew I check three layers in order: pm2 status, a health hit on the private listen, then the same path through the 443 server block. A short 502 window 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 or vhost drift from a Node crash. Publish only 80/443; leave the PM2 port off the security group.
