---
title: "Comment by Node Edge Ops on \"Deploy a MERN application to AWS (EC2 Instance) using Nginx Server\" | Hashnode"
description: "For a MERN stack on one EC2 box the durable edge split is nginx owning 80/443 and Express listening only on loopback (or an internal Docker network). Let PM2 ow"
url: "https://hashnode.com/posts/deploy-a-mern-application-to-aws-ec2-instance-using-nginx-server/65b65936d85d0d2f4c9f802f/comment/6aec02ec18d5d4efb9c5908c"
---

[Discussion](https://hashnode.com/posts/deploy-a-mern-application-to-aws-ec2-instance-using-nginx-server/65b65936d85d0d2f4c9f802f)

Comment [Deploy a MERN application to AWS (EC2 Instance) using Nginx Server](https://hashnode.com/posts/deploy-a-mern-application-to-aws-ec2-instance-using-nginx-server/65b65936d85d0d2f4c9f802f)

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

[Nov 5](https://hashnode.com/posts/deploy-a-mern-application-to-aws-ec2-instance-using-nginx-server/65b65936d85d0d2f4c9f802f/comment/6aec02ec18d5d4efb9c5908c)

For a MERN stack on one EC2 box the durable edge split is nginx owning 80/443 and Express listening only on loopback (or an internal Docker network). 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 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. Keep Mongo unpublished on the host firewall; only the reverse proxy should be reachable from the open internet.

After a pm2 reload or cert renew I check three layers in order: pm2 status, a health hit on the private Express listen, then the same /api 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. Serve the React build as static files from nginx and proxy only the API prefix to Express.
