---
title: "Discussion on \"Deploying Nodejs app on Ubuntu server with pm2 & nginx\" | Hashnode"
description: "Discussion on \"Deploying Nodejs app on Ubuntu server with pm2 & nginx\". Deploying a Node.js application on an Ubuntu server can be a daunting task, but with the right tools, it can be done with ease. In this tutorial, we will go over how to deploy a Node.js application using the process manager pm2 and the web server Ngi..."
url: "https://hashnode.com/posts/deploying-nodejs-app-on-ubuntu-server-with-pm2-nginx/63f87fc718386255bbf8ac3e"
---

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

Discussion

# [Deploying Nodejs app on Ubuntu server with pm2 & nginx](https://bwiza.hashnode.dev/deploying-nodejs-app-on-ubuntu-server-with-pm2-nginx?utm_source=hashnode&utm_medium=feed)

Deploying a Node.js application on an Ubuntu server can be a daunting task, but with the right tools, it can be done with ease. In this tutorial, we will go over how to deploy a Node.js application using the process manager pm2 and the web server Ngi...

Feb 24, 2023 · 3 min read · bwiza.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#pm2](https://hashnode.com/tag/pm2)
-   [#nginx](https://hashnode.com/tag/nginx)
-   [#linux](https://hashnode.com/tag/linux)

## Written by

[Bwiza Charlotte](https://hashnode.com/@bwiza)

@bwiza

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

Tech | Gender Equity | Community

## Responses 1

Comments are turned off for this post.

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

[Nov 5](https://hashnode.com/posts/deploying-nodejs-app-on-ubuntu-server-with-pm2-nginx/63f87fc718386255bbf8ac3e/comment/6aec0b1fb1efaf4d45ab5e32)

On Ubuntu a Node app behind nginx is strongest when the reverse proxy alone binds 80/443 and Express (or Nest) listens only on loopback. 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 for keepalive into Node, and always forward Host plus X-Forwarded-For / X-Forwarded-Proto so redirects and secure cookies stay on the public scheme. Keep any database port closed on the host firewall; only the reverse proxy should be reachable from the open internet.

Ops check after a pm2 reload or cert renew: pm2 status, a health hit on the private listen, then the same API path through the 443 server block. A brief 502 spike 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 drift from a Node crash, and expose a readiness probe that fails when the event loop is wedged rather than when the socket merely accepts.
