---
title: "Discussion on \"🚀How I Deployed My Node.js Backend to EC2 with Nginx, SSL & PM2\" | Hashnode"
description: "Discussion on \"🚀How I Deployed My Node.js Backend to EC2 with Nginx, SSL & PM2\". Learn how to deploy your Node.js backend to AWS EC2 using Nginx as a reverse proxy, add HTTPS with Certbot, and keep your app running with PM2. Full step-by"
url: "https://hashnode.com/posts/how-i-deployed-my-nodejs-backend-to-ec2-with-nginx-ssl-and-pm2/688f84d099b037c3657a2b66"
---

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

Discussion

# [🚀How I Deployed My Node.js Backend to EC2 with Nginx, SSL & PM2](https://sangammundhe.hashnode.dev/how-i-deployed-my-nodejs-backend-to-ec2-with-nginx-ssl-and-pm2?utm_source=hashnode&utm_medium=feed)

Learn how to deploy your Node.js backend to AWS EC2 using Nginx as a reverse proxy, add HTTPS with Certbot, and keep your app running with PM2. Full step-by

Aug 3, 2025 · 4 min read · sangammundhe.hashnode.dev  
Read the article

-   [#devops](https://hashnode.com/tag/devops)
-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#aws](https://hashnode.com/tag/aws)
-   [#ec2](https://hashnode.com/tag/ec2)
-   [#nginx](https://hashnode.com/tag/nginx)
-   [#pm2](https://hashnode.com/tag/pm2)
-   [#deployment](https://hashnode.com/tag/deployment)
-   [#virtual-machine](https://hashnode.com/tag/virtual-machine)
-   [#cloud-computing](https://hashnode.com/tag/cloud-computing)

## Written by

[Sangam Mundhe](https://hashnode.com/@sangammundhe)

@sangammundhe · India

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

## Responses 1

Markdown supported · ⌘↵ to post

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

[Nov 5](https://hashnode.com/posts/how-i-deployed-my-nodejs-backend-to-ec2-with-nginx-ssl-and-pm2/688f84d099b037c3657a2b66/comment/6aebc81eea0102533312b9d6)

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.
