---
title: "Discussion on \"Deploy a MERN application to AWS (EC2 Instance) using Nginx Server\" | Hashnode"
description: "Discussion on \"Deploy a MERN application to AWS (EC2 Instance) using Nginx Server\". What is MERN Application ?\nMERN stands for MongoDB, Express, React, Node, after the four key technologies that make up the stack.\n\nMongoDB - Document database (BSON object or Binary JSON)\n\nExpress - Open source Node.js web framework\n\nReact - A client..."
url: "https://hashnode.com/posts/deploy-a-mern-application-to-aws-ec2-instance-using-nginx-server/65b65936d85d0d2f4c9f802f"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Deploy a MERN application to AWS (EC2 Instance) using Nginx Server](https://rohanwrite.dev/deploy-a-mern-application-to-aws-ec2-instance-using-nginx-server?utm_source=hashnode&utm_medium=feed)

What is MERN Application ? MERN stands for MongoDB, Express, React, Node, after the four key technologies that make up the stack. MongoDB - Document database (BSON object or Binary JSON) Express - Open source Node.js web framework React - A client...

Jan 28, 2024 · 5 min read · rohanwrite.dev  
Read the article

-   [#aws](https://hashnode.com/tag/aws)
-   [#aws-ec2](https://hashnode.com/tag/aws-ec2)
-   [#nginx](https://hashnode.com/tag/nginx)
-   [#app-deployment-on-aws](https://hashnode.com/tag/app-deployment-on-aws)
-   [#devops](https://hashnode.com/tag/devops)
-   [#mern](https://hashnode.com/tag/mern)

## Written by

[Rohan Mishra](https://hashnode.com/@rohanmishra411)

@rohanmishra411

  
[View profile](https://hashnode.com/@rohanmishra411)

Student ..Passionate about tech

## Responses 1

Markdown supported · ⌘↵ to post

[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.
