---
title: "Discussion on \"How to Host Node.js on a VPS Using Nginx and PM2\" | Hashnode"
description: "Discussion on \"How to Host Node.js on a VPS Using Nginx and PM2\". Deploying a Node.js application to a Virtual Private Server (VPS) can feel intimidating if you are used to one-click platform-as-a-service (PaaS) providers. However, hosting on your own VPS gives you"
url: "https://hashnode.com/posts/how-to-host-node-js-on-a-vps-using-nginx-and-pm2/6a1c2ee6bbf6e68381774df7"
---

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

Discussion

# [How to Host Node.js on a VPS Using Nginx and PM2](https://host-nodejs-application-for-free.hashnode.dev/how-to-host-node-js-on-a-vps-using-nginx-and-pm2?utm_source=hashnode&utm_medium=feed)

Deploying a Node.js application to a Virtual Private Server (VPS) can feel intimidating if you are used to one-click platform-as-a-service (PaaS) providers. However, hosting on your own VPS gives you

May 31 · 5 min read · host-nodejs-application-for-free.hashnode.dev  
Read the article

## Written by

[VPS Malaysia Blogs](https://hashnode.com/@vps-malaysia-blogs)

@vps-malaysia-blogs

  
[View profile](https://hashnode.com/@vps-malaysia-blogs)

## Responses 1

Comments are turned off for this post.

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

[Nov 5](https://hashnode.com/posts/how-to-host-node-js-on-a-vps-using-nginx-and-pm2/6a1c2ee6bbf6e68381774df7/comment/6aebf1c9dbab450f512a2362)

On a bare VPS the durable split is nginx owning 80/443 and one PM2 listen bound on loopback. Let PM2 own cluster fan-out on that single port — listing every worker in an nginx upstream doubles fail surfaces and breaks session affinity when a process drains. Keep 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.

After pm2 reload or a cert renew I check three layers in order: pm2 status, a health hit on the private listen, then the same 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. Publish only 80/443 on the firewall; leave the PM2 port local.
