1
Install and build
Install exactly the locked dependencies, run project checks, and create the production build.
cd /var/www/<app-name>
npm ci
npm run build2
Start with PM2
Run the compiled NestJS entry point under a stable process name.
pm2 start dist/main.js --name <app-name>
pm2 save
pm2 startupNote: Run the additional sudo command printed by pm2 startup; it is specific to your user and host.
3
Add the Nginx reverse proxy
Proxy the public domain to the local NestJS port and preserve request metadata.
server {
listen 80;
server_name <domain>;
location / {
proxy_pass http://127.0.0.1:<port>;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}4
Enable and validate Nginx
Link the site only after reviewing it, then test syntax before reload.
sudo ln -s /etc/nginx/sites-available/<app-name> /etc/nginx/sites-enabled/<app-name>
sudo nginx -t && sudo systemctl reload nginx5
Issue the TLS certificate
Use Certbot's Nginx integration after DNS and HTTP are working.
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d <domain>6
Check runtime health
Verify HTTPS, the process, proxy logs, and certificate renewal.
curl -I https://<domain>
pm2 status
sudo certbot renew --dry-runFinal verification
- ✓ HTTPS returns the expected status without a certificate warning
- ✓ PM2 shows the application online
- ✓ sudo nginx -t succeeds
- ✓ The NestJS port is not publicly exposed