Monday, September 22, 2025Deploy NextJS 15 with Node and Nginx
Keven Client A. Cataluña @LinkedIn
Introduction

This guide explains how to deploy a NextJS application using Node.js and Nginx. It covers building the application, resolving port conflicts, managing the Node.js process with PM2, creating a new Nginx site configuration, and verifying if the deployment is working correctly.

Steps1. Clone the NextJS project into the web root directory
/var/www/html
    git clone git@github_development:kevenclient/hookre-web.git
  
2. Build the project
/var/www/html/hookre-web
    npm run build
  
3. Change the port to fix the address already in use :::3000 error Error
/var/www/html/hookre-web
    npm run start
  
      > hookre-web@0.1.0 start
  > next start -p 3000

   ⨯ Failed to start server
  Error: listen EADDRINUSE: address already in use :::3000
      at <unknown> (Error: listen EADDRINUSE: address already in use :::3000)
      at new Promise (<anonymous>) {
    code: 'EADDRINUSE',
    errno: -98,
    syscall: 'listen',
    address: '::',
    port: 3000
  }
  
Solution
package.json
    {
  ...
  "scripts": {
    "dev": "next dev --turbopack",
    "build": "next build --turbopack",
    "start": "next start -p 3001", // Changed the default port
    "lint": "eslint",
    "socket.io-server": "npx tsx socket.io-server"
  },
  ...
}
  
4. Install the latest version of PM2 globally
    npm install pm2@latest -g
  
5. Create a PM2 configuration file with the following content
ecosystem.config.cjs
    module.exports = {
  apps : [{
    name: 'hookre.get-go.dev',
    script: 'npm run start',
  }],
}
  
6. Start the application with PM2
    pm2 start ecosystem.config.cjs
  
      [PM2][WARN] Applications hookre.get-go.dev not running, starting...
  [PM2] App [hookre.get-go.dev] launched (1 instances)
  ┌────┬────────────────────┬──────────┬─────────┬───────────┬──────────┬──────────┐
  │ id │ name               │ mode     │ restart │ status    │ cpu      │ memory   │
  ├────┼────────────────────┼──────────┼─────────┼───────────┼──────────┼──────────┤
  │ 0  │ hookre.get-go.dev  │ fork     │ 0       │ online    │ 0%       │ 3.0mb    │
  └────┴────────────────────┴──────────┴─────────┴───────────┴──────────┴──────────┘
  
7. Create a new Nginx site configuration
/etc/nginx/sites-available/hookre_web
    server {
  server_name hookre.get-go.dev;

  location / {
    proxy_pass http://localhost:3001;
    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;
  }
}
  
8. Create a symlink to enable the new site configuration
/etc/nginx/sites-enabled
    sudo ln -s /etc/nginx/sites-available/kakeibo
  
9. Test the Nginx configuration
    sudo nginx -t
  
      nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful
  
10. Reload Nginx to apply the changes
    sudo systemctl reload nginx
  
11. Verify the deployment by navigating to https://hookre.get-go.dev and you should see the NextJS 15 project