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 git clone git@github_development:kevenclient/hookre-web.git
npm run build
address already in use :::3000 error Error 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
}
{
...
"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"
},
...
}
npm install pm2@latest -g
module.exports = {
apps : [{
name: 'hookre.get-go.dev',
script: 'npm run start',
}],
}
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 │
└────┴────────────────────┴──────────┴─────────┴───────────┴──────────┴──────────┘
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;
}
}
symlink to enable the new site configuration sudo ln -s /etc/nginx/sites-available/kakeibo
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl reload nginx
https://hookre.get-go.dev and you should see the NextJS 15 project 