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.
Node Edge Ops
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.