
Hosting Node.js and Next.js on a VPS: A Complete Guide
Learn the essential steps to host Node.js on a VPS, configure a reverse proxy, and achieve zero-downtime deployments natively using bipanel.
Hosting a Node.js application on a VPS basically means running your app as a background service (daemon) and putting a reverse proxy in front of it. Whether you use plain Node.js or a Server-Side Rendered (SSR) Next.js project, you need to take traffic from ports 80 and 443 and route it safely to your app's internal port (like 3000).
Traditional hosting panels are often designed around PHP, so deploying modern JavaScript and TypeScript apps usually requires complex add-ons or manual terminal work. In this post, we will look at the technical basics of hosting Node.js apps on a server and show you how to make this process plugin-free, zero-downtime, and Git-integrated using bipanel's built-in tools.
Why Do Node.js Apps Need a Reverse Proxy?
While it is technically possible to run your Node.js app directly on port 80 (HTTP) or 443 (HTTPS), this is never recommended for security or performance. There are three main reasons:
- Security and privileges: On Linux systems, listening on ports below 1024 requires root privileges. Running your app as root means a potential vulnerability could compromise the entire server.
- SSL/TLS management: Managing and renewing SSL certificates inside Node.js is cumbersome. Automated certificate providers like Let's Encrypt work much better with web servers (like Nginx or Apache).
- Hosting multiple apps: If you want to host multiple websites or apps on the same server (for example, a WordPress blog and a Next.js app), you need a traffic manager that shares ports 80 and 443.
For these reasons, the standard architecture relies on Nginx or Apache at the front to handle traffic, serve static files, terminate SSL encryption, and pass only the dynamic requests to the Node.js process running internally (e.g., 127.0.0.1:3000).
Manual Setup: The Traditional Method
Before moving to modern automation tools, it helps to understand what happens in the background. In a manual setup, the process looks like this:
1. Daemonizing the App (systemd)
To make your app start automatically when the server reboots and restart if it crashes, you need to create a systemd service file.
# /etc/systemd/system/myapp.service
[Unit]
Description=Next.js Application
After=network.target
[Service]
User=appuser
WorkingDirectory=/home/appuser/myapp
ExecStart=/usr/bin/npm run start
Restart=always
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
You use systemctl enable myapp to enable the service and systemctl start myapp to start it.
2. Nginx Reverse Proxy Configuration
While the app runs internally on port 3000, Nginx is configured to route incoming external requests to this port. For apps that require WebSocket support, passing Upgrade headers is also mandatory.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
The Challenges of the Manual Method
This setup might look simple at first, but things get complicated during updates. When you release a new version, run git pull, and execute npm run build, your app will go down, or users will see a 502 Bad Gateway error for several seconds (downtime). Also, preventing port conflicts for every new project, manually configuring SSL certificates, and tracking logs is a serious waste of time.
Zero-Downtime Deployments with bipanel
bipanel hosts apps like Node.js, Next.js, Python, Ruby, and Go natively alongside PHP sites, without needing any extra plugins. Your app's build, startup, port assignment, and reverse proxy configuration are managed entirely automatically.
The biggest advantage is its zero-downtime deployment capability. Eliminating the 502 errors found in traditional methods, this architecture works as follows:
- Release folders (a/b slots): When a new deployment is triggered, bipanel does not stop the currently running app. It pulls the code into a new release folder.
- Background builds: Dependency installation (
npm install) and building (npm run build) happen in this new folder in the background. - Health checks: The app is started on a new internal port. bipanel checks whether the app returns a healthy response over HTTP or TCP.
- Traffic switch: If the app is healthy, the reverse proxy instantly switches to the new port. The old process is shut down. Visitors experience no downtime.
- One-click rollback: If something goes wrong with the new version, you can revert to the previous working version with a single click from the panel.
Step by Step: Deploying Node.js and Next.js in bipanel
If you do not have a server yet, prepare a clean Ubuntu 24.04 LTS (or AlmaLinux 9 for the Red Hat family) server. To install bipanel, simply run this command as root:
curl -fsSL https://bipanel.io/install.sh | sudo bash -s -- --hostname server.example.com --email [email protected]
The installation takes about 15 minutes. Once finished, log into the admin panel and create a hosting account. Then, switch to the user panel and follow these steps:
1. Preparing the App Environment
Go to the Apps section in the user panel and add a new Node.js application. bipanel detects your framework and suggests default commands.
- App language and version: Choose the Node.js version your app requires from the verified official builds available in your account.
- Environment variables (.env): Safely add environment variables like database connections or API keys through the panel interface. These variables are injected directly into the app process.
2. Git Connection and Automatic Deployment
While you can upload your files via FTP or the File Manager, the most robust method is using the Git integration.
- Connect your GitHub, GitLab, Bitbucket, or Gitea account through the panel.
- Select your repository and the branch you want to deploy (for example,
mainorproduction). - bipanel automatically adds a deploy key and a signed webhook to your repository.
Now, the moment you write your code locally and push it (git push), the webhook reaches the server. bipanel pulls the code, builds it, runs a health check, and updates your app with zero downtime.
3. Build and Start Commands
For frameworks like Next.js, build steps are critical. You can customize these commands in the panel according to your project:
- Build command:
npm install && npm run build - Start command:
npm run start
If you are just running an API (like Express.js), you can leave the build command empty and set the start command to node server.js.
4. Reverse Proxy and WebSocket Support
When you start the app, bipanel assigns an available internal port on the server to your app (for example, 3004). The Nginx or Apache reverse proxy configuration is generated automatically.
If your app requires WebSocket connections like Socket.io, the reverse proxy is natively configured to pass this traffic directly to your app without interruption.
Monitoring, Logs, and Troubleshooting
Deploying an app is only half the job; keeping it running is the real challenge. bipanel provides tools that make app management easier:
- Live logs: You can watch your app's
stdoutandstderroutput live in your browser. Seeing errors printed to the console instantly speeds up troubleshooting. - Automatic restarts: If your app crashes due to a memory leak or an uncaught exception, bipanel's process manager detects it, restarts it with backoff, and notifies you.
- Preview environments (Pro): If you use bipanel Pro, a separate preview address is automatically created for every pull request you open on GitHub or GitLab. Your team can test changes on this temporary address before pushing them live.
Conclusion
Hosting Node.js or Next.js on a VPS is an error-prone and time-consuming process when managed with manual configurations. Setting up a reverse proxy, managing services, and building CI/CD pipelines require serious system administration effort.
bipanel eliminates all this complexity, allowing developers to focus solely on their code. With its plugin-free native structure, Git integration, and health-checked zero-downtime deployment architecture, you can host modern web applications securely.
To set up a modern hosting infrastructure on your own server, you can install bipanel right away from /en/download. The Community edition, which is completely free for up to 3 hosting accounts, includes all the core app hosting and Git deployment features mentioned in this post. For more accounts, agency features, and advanced preview environments, check out our Pro plans on the /en/pricing page.
Frequently asked questions
Which operating system should I choose for Node.js apps?
If you are setting up a new server, we recommend Ubuntu 24.04 LTS for its long-term support and broad package compatibility. If you are familiar with the Red Hat family, AlmaLinux 9 is also an excellent and fully supported choice for hosting Node.js.
Should I deploy my Next.js project as static or with Node.js?
If your project only has static pages (Static Export), you can serve the files directly through the web server. However, if you use Server-Side Rendering (SSR), API routes, or Image Optimization, you must run your app as a Node.js service.
What causes a 502 Bad Gateway error?
This error indicates that the front-end web server (reverse proxy) cannot reach the Node.js app running in the background. Your app might have crashed, it might not be listening on the specified internal port, or an error might have occurred during the build phase; you should check the live logs.
Do I need to install a plugin for Node.js in bipanel?
No. bipanel supports Node.js, Python, Ruby, and Go apps by default without needing any plugins. The necessary port assignments and reverse proxy configurations are managed automatically by the panel.
How do zero-downtime deployments work?
When you publish a new version, bipanel pulls the code into a new folder and builds it in the background. After the app is started on a new port and passes a health check (HTTP/TCP), traffic is instantly routed to this new version, so visitors experience no downtime.
Read this article in Turkish: VPS Sunucuda Node.js ve Next.js Barındırma Rehberi


