Node.js app on CloudPanel shows 502 or keeps restarting: PM2 fixes
Your Node.js site in CloudPanel shows 502 Bad Gateway, or it works for a while and then dies, or it's gone after every server reboot. For a Node.js site, CloudPanel's Nginx simply forwards visitors to your app on a local port. A 502 means Nginx knocked on that port and nobody answered. This guide shows how to find out why. Setting up a new app? See How to host a Node.js app on CloudPanel with PM2.
Step 1: Compare the ports
When you created the Node.js site, you entered an App Port (for example 3000). Nginx sends traffic to. Your app must listen on exactly that port. Check what's listening:
Step 2: Is PM2 running the app?
Log in as the site user (PM2 is per user, so root's PM2 list is a different one):
Step 3: Read the app's error log
The usual crash reasons:
Step 4: App gone after a reboot
PM2 doesn't remember your apps across reboots unless you tell it to. As the site user, after the app runs correctly:
prints a command that starts with . Copy that exact line and run it as root. Then reboot once to test.
Step 5: App dies under load or every few hours
Often the server runs out of memory and Linux kills the biggest process. Check:
If you see your app there, add swap or more RAM, or limit the app's memory so PM2 restarts it cleanly before the system kills it:
Also check Fix 502 Bad Gateway in CloudPanel for general 502 causes.
Quick checklist
Sources: PM2: quick start · PM2: startup script · CloudPanel: site:add:nodejs
More CloudPanel troubleshooting
Applies to CloudPanel v2 on Ubuntu and Debian, October 2026. Replace 3000 with your site's App Port.
Your Node.js site in CloudPanel shows 502 Bad Gateway, or it works for a while and then dies, or it's gone after every server reboot. For a Node.js site, CloudPanel's Nginx simply forwards visitors to your app on a local port. A 502 means Nginx knocked on that port and nobody answered. This guide shows how to find out why. Setting up a new app? See How to host a Node.js app on CloudPanel with PM2.
Step 1: Compare the ports
When you created the Node.js site, you entered an App Port (for example 3000). Nginx sends traffic to
Code:
127.0.0.1:3000Code:
ss -tlnp | grep node- Nothing listed: the app isn't running. Go to Step 2.
- Listening on another port (say 8080): change your app's port, or change the site's App Port in CloudPanel to match.
- Listening on only, or on a specific external IP: make the app listen onCode:
::1(orCode:127.0.0.1). Many frameworks readCode:0.0.0.0andCode:PORTenvironment variables.Code:HOST
Step 2: Is PM2 running the app?
Log in as the site user (PM2 is per user, so root's PM2 list is a different one):
Code:
pm2 list- online: running. If you still get 502, recheck the port (Step 1).
- errored or a high restart count (↺): the app crashes on start. Go to Step 3.
- Empty list: the app was never started as this user, or PM2 lost it after a reboot (Step 4).
Step 3: Read the app's error log
Code:
pm2 logs --lines 50- Cannot find module '...': dependencies aren't installed. Run (orCode:
npm ci) in the app folder as the site user.Code:npm install
- EADDRINUSE: the port is already taken, often by an old copy of the app. (as the site user), then start it once.Code:
pm2 delete all
- Missing environment variables or file: copy them over from your old server or your project's example file.Code:
.env
- Wrong Node version: check . Choose the Node.js version your app needs in the site's settings.Code:
node -v
- Build not run: Next.js, Nuxt and similar apps need beforeCode:
npm run build.Code:npm start
Code:
pm2 restart allStep 4: App gone after a reboot
PM2 doesn't remember your apps across reboots unless you tell it to. As the site user, after the app runs correctly:
Code:
pm2 save
pm2 startupCode:
pm2 startupCode:
sudo env PATH=...Step 5: App dies under load or every few hours
Often the server runs out of memory and Linux kills the biggest process. Check:
Code:
free -h
dmesg -T | grep -i 'killed process' | tailCode:
pm2 start npm --name myapp --max-memory-restart 400M -- startQuick checklist
- (as the site user) shows the app online.Code:
pm2 list
- shows it on the App Port, on 127.0.0.1 or 0.0.0.0.Code:
ss -tlnp | grep node
- on the server returns a response.Code:
curl -I http://127.0.0.1:3000
- and the startup command are done.Code:
pm2 save
Sources: PM2: quick start · PM2: startup script · CloudPanel: site:add:nodejs
More CloudPanel troubleshooting
- Installation failed: common install errors
- Can't log in: port 8443, password and 2FA
- Site shows 403 Forbidden or 404
- Too many redirects or mixed content after SSL
- PHP extension missing / enable ionCube
- WordPress asks for FTP or can't update plugins
- Varnish showing old pages or breaking logins
- Restore a site from a backup
- SSH or SFTP login fails
- Site hacked: find malware and clean up
- clpctl errors: not found, wrong user, quoting
Applies to CloudPanel v2 on Ubuntu and Debian, October 2026. Replace 3000 with your site's App Port.

