Every time I set up a new VPS, I remember the general process — and then forget half of the commands a few months later. So I decided to write this guide as my own production VPS checklist: how to take a VPS, deploy a frontend and backend, put Nginx in front of them, connect domains, enable HTTPS, and make sure everything survives a reboot.
This is not a theoretical DevOps tutorial. It is the practical workflow I use when hosting a real website on a Linux VPS.
The Architecture
The basic architecture is simple. The public internet talks to Nginx on ports 80 and 443. Nginx then forwards requests to applications running privately on localhost.
1Internet
2 ↓
3DNS
4 ↓
5VPS
6 ↓
7Nginx :80 / :443
8 ├── crm.example.com → Next.js :3000
9 └── api.example.com → Node.js :8080The important idea is that users do not need direct access to ports 3000 or 8080. Nginx is the public entry point, while the applications can listen only on localhost.
What I Need on the VPS
- Ubuntu VPS
- Node.js and npm
- PM2 for keeping Node.js applications alive
- Nginx as the reverse proxy
- A domain name
- DNS records pointing to the VPS
- Certbot and Let's Encrypt for HTTPS
- A firewall allowing SSH, HTTP, and HTTPS
Step 1: Connect to the VPS
The first step is connecting to the server through SSH.
1ssh root@YOUR_SERVER_IPAfter connecting, I usually check the operating system and server resources before doing anything else.
1uname -a
2cat /etc/os-release
3free -h
4df -h
5uptimeStep 2: Update the Server
Before installing anything, update the package lists and upgrade installed packages.
1apt update
2apt upgrade -yIt is also useful to know which services are already installed and running, especially on a VPS that may have been configured by a hosting provider.
1systemctl --type=service --state=runningStep 3: Check Which Ports Are Already in Use
This is one of the most important commands to remember. Before starting Nginx, check ports 80 and 443. Also check the ports where your applications are supposed to run.
1ss -lntp
2ss -lntp | grep -E ':80|:443|:3000|:8080'If another web server such as OpenLiteSpeed is already listening on port 80 or 443, Nginx cannot bind to those ports.
1systemctl status lshttpd
2systemctl status nginxOn my VPS, OpenLiteSpeed was previously installed. Since I wanted Nginx to be the web server, I stopped and disabled OpenLiteSpeed before starting Nginx.
1systemctl stop lshttpd
2systemctl disable lshttpdIf an old process continues running after the service is stopped, inspect it before killing anything. Never blindly kill processes on a production server.
Step 4: Deploy the Applications
I deploy the frontend and backend separately. For example, the Next.js frontend runs on port 3000 and the Node.js backend runs on port 8080.
1# Frontend
2cd /var/www/crm-client
3npm install
4npm run build
5
6# Backend
7cd /var/www/crm-api
8npm install
9npm run buildBefore involving Nginx, I always test each application directly from the VPS.
1curl -I http://127.0.0.1:3000
2curl -i http://127.0.0.1:8080This separates application problems from Nginx, DNS, and SSL problems. If the application itself does not work locally, there is no point debugging DNS yet.
"Debug from the inside out: application → Nginx → DNS → browser."
Step 5: Keep the Applications Alive with PM2
A Node.js process should not depend on an SSH terminal staying open. PM2 keeps applications running, restarts them when necessary, and can restore them after a server reboot.
1npm install -g pm2Start the applications with PM2:
1pm2 start npm --name crm-client -- start
2pm2 start npm --name crm-api -- startUseful PM2 commands I want to remember:
1pm2 list
2pm2 status
3pm2 logs
4pm2 logs crm-client
5pm2 logs crm-api
6pm2 restart crm-client
7pm2 restart crm-api
8pm2 stop crm-client
9pm2 delete crm-clientAfter everything is working, save the process list and configure PM2 to start during boot.
1pm2 save
2pm2 startupPM2 will print another command after pm2 startup. Run that command exactly as provided, then run pm2 save again.
Step 6: Install and Start Nginx
1apt install nginx -y
2systemctl enable nginx
3systemctl start nginx
4systemctl status nginxVerify that Nginx is actually listening on the public HTTP port:
1ss -lntp | grep -E ':80|:443'Step 7: Configure Nginx as a Reverse Proxy
Instead of exposing ports 3000 and 8080 directly to the internet, Nginx receives requests and forwards them to the correct application based on the hostname.
1nano /etc/nginx/sites-available/crm.conf1server {
2 listen 80;
3 listen [::]:80;
4
5 server_name crm.example.com;
6
7 location / {
8 proxy_pass http://127.0.0.1:3000;
9 proxy_http_version 1.1;
10
11 proxy_set_header Host $host;
12 proxy_set_header X-Real-IP $remote_addr;
13 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14 proxy_set_header X-Forwarded-Proto $scheme;
15
16 proxy_set_header Upgrade $http_upgrade;
17 proxy_set_header Connection "upgrade";
18 }
19}
20
21server {
22 listen 80;
23 listen [::]:80;
24
25 server_name api.example.com;
26
27 location / {
28 proxy_pass http://127.0.0.1:8080;
29 proxy_http_version 1.1;
30
31 proxy_set_header Host $host;
32 proxy_set_header X-Real-IP $remote_addr;
33 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
34 proxy_set_header X-Forwarded-Proto $scheme;
35
36 proxy_set_header Upgrade $http_upgrade;
37 proxy_set_header Connection "upgrade";
38 }
39}Enable the site and remove the default Nginx configuration if it is not needed.
1ln -sf /etc/nginx/sites-available/crm.conf /etc/nginx/sites-enabled/crm.conf
2rm -f /etc/nginx/sites-enabled/defaultAlways test the configuration before reloading Nginx.
1nginx -t
2systemctl reload nginx"Never change a production Nginx configuration without running nginx -t first."
Step 8: Configure DNS
Now the domain needs to point to the VPS. For this setup, I use A records for the domains.
1crm.example.com → A → YOUR_VPS_IP
2api.example.com → A → YOUR_VPS_IPDNS changes can take time to appear everywhere depending on DNS caching and TTL. I verify the records from the server before moving on to SSL.
1dig crm.example.com +short
2dig api.example.com +shortThe returned IP should be the VPS IP that is running Nginx.
"DNS must point to the correct server before HTTP-01 SSL validation can succeed."
Step 9: Test Nginx Before HTTPS
Before adding SSL, I test the domains over plain HTTP. This confirms that DNS and Nginx are working independently of certificates.
1curl -I http://crm.example.com
2curl -i http://api.example.comA backend returning 404 for / is not necessarily a problem. If the response comes from Express or NestJS, it can actually confirm that Nginx successfully reached the backend. The important thing is to test an endpoint that your API is expected to provide.
Step 10: Install Certbot
Let's Encrypt provides the certificates, while Certbot handles certificate issuance and renewal.
1apt install certbot python3-certbot-nginx -y
2certbot --versionThe Nginx plugin is important if I want Certbot to automatically configure Nginx. If Certbot says that the Nginx plugin is not installed, install python3-certbot-nginx first.
Step 11: Generate the SSL Certificate
1certbot --nginx -d crm.example.com -d api.example.comCertbot can modify the Nginx configuration to add HTTPS and redirect HTTP to HTTPS. After it finishes, I test both domains again.
1curl -I https://crm.example.com
2curl -i https://api.example.comStep 12: Understand Where the Certificates Live
I can inspect the certificates managed by Certbot with:
1certbot certificatesCertificates are normally stored under /etc/letsencrypt/live/. I should not manually edit files inside that directory. Nginx references the certificate and private key there.
1ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
2ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;Step 13: Test Automatic Certificate Renewal
Getting HTTPS working once is not enough. Certificates expire, so renewal must work automatically.
1certbot renew --dry-runA successful dry run means Certbot was able to simulate the renewal process. I should still make sure the systemd timer responsible for running Certbot is enabled.
1systemctl list-timers | grep certbotStep 14: Configure the Firewall
If UFW is being used, SSH must be allowed before enabling the firewall. Otherwise, I can accidentally lock myself out of the VPS.
1ufw status
2ufw allow OpenSSH
3ufw allow 'Nginx Full'
4ufw enable
5ufw statusThe basic public ports I normally need are SSH for administration and HTTP/HTTPS for the website. Application ports such as 3000 and 8080 do not need to be publicly exposed when Nginx is proxying to localhost.
The Most Important Security Detail
If the applications only listen on 127.0.0.1, they are not directly reachable from the public internet. Nginx is the public gateway.
1ss -lntp | grep -E ':3000|:8080|:80|:443'Ideally, Nginx owns ports 80 and 443, while the applications listen on localhost ports such as 3000 and 8080.
How to Debug When Something Breaks
When a website stops working, I try not to randomly restart everything. I check each layer separately.
1. Is the application running?
1pm2 status
2pm2 logs2. Does the application respond locally?
1curl -I http://127.0.0.1:3000
2curl -i http://127.0.0.1:80803. Is Nginx running?
1systemctl status nginx
2nginx -t4. Is Nginx listening on the correct ports?
1ss -lntp | grep -E ':80|:443'5. Is DNS pointing to the correct VPS?
1dig example.com +short
2dig api.example.com +short6. What does Nginx say?
1tail -f /var/log/nginx/access.log
2tail -f /var/log/nginx/error.log7. What does the application say?
1pm2 logs crm-client
2pm2 logs crm-api"Don't guess. Find which layer is broken first."
Common Problems I Want to Remember
Port 80 Already in Use
If Nginx reports 'Address already in use', another process is already listening on port 80.
1ss -lntp | grep :80
2ss -lntp | grep :443Find the service that owns the port before stopping it. On a VPS previously managed by another hosting stack, this may be another web server such as OpenLiteSpeed.
Certbot Authentication Failed
If Let's Encrypt returns a 404 or unauthorized error during HTTP validation, check DNS first. The certificate authority must be able to reach the correct VPS over HTTP and retrieve the ACME challenge.
1dig example.com +short
2curl -I http://example.comAlso check that Nginx is serving the correct server block and that nothing else is intercepting port 80.
Backend Returns 404 on /
A 404 response from the backend root URL does not automatically mean the deployment is broken. APIs often do not define a GET / route. Test a real health-check or API endpoint instead.
1curl -i https://api.example.com/health
2curl -i https://api.example.com/api/usersNginx Configuration Changed but Nothing Happened
1nginx -t
2systemctl reload nginxA reload applies configuration changes without unnecessarily stopping the running Nginx service.
Browser Looks Wrong but curl Works
If curl shows the expected HTTPS response but the browser behaves differently, test in a private window and check the browser cache, DNS cache, redirects, and certificate details before assuming the server is broken.
Useful Commands Cheat Sheet
1# Services
2systemctl status nginx
3systemctl restart nginx
4systemctl reload nginx
5systemctl status lshttpd
6
7# Nginx
8nginx -t
9nginx -T
10
11# Ports
12ss -lntp
13ss -lntp | grep -E ':80|:443|:3000|:8080'
14
15# Processes
16ps aux | grep nginx
17ps aux | grep node
18
19# PM2
20pm2 status
21pm2 logs
22pm2 restart all
23pm2 save
24pm2 startup
25
26# DNS
27dig example.com +short
28dig api.example.com +short
29
30# HTTP/HTTPS
31curl -I http://example.com
32curl -I https://example.com
33curl -i https://api.example.com
34
35# Nginx logs
36tail -f /var/log/nginx/access.log
37tail -f /var/log/nginx/error.log
38
39# SSL
40certbot certificates
41certbot renew --dry-run
42
43# Firewall
44ufw status
45ufw status numberedMy Production Deployment Checklist
- VPS is accessible through SSH
- Server packages are updated
- Node.js and npm are installed
- Applications are deployed
- Applications work locally with curl
- PM2 is running the applications
- PM2 startup is configured
- No unwanted service owns ports 80 or 443
- Nginx is installed and running
- Nginx configuration passes nginx -t
- Nginx proxies each domain to the correct application
- DNS A records point to the VPS
- HTTP requests reach the correct application
- Certbot and the Nginx plugin are installed
- HTTPS certificates are issued
- HTTP redirects to HTTPS
- certbot renew --dry-run succeeds
- Firewall allows SSH and web traffic
- Application ports are not unnecessarily exposed publicly
- Nginx and PM2 logs are accessible
The Mental Model I Want to Remember
When a user visits my website, the request travels through several layers:
1Browser
2 ↓
3DNS
4 ↓
5VPS public IP
6 ↓
7Nginx :80 / :443
8 ↓
9server_name decides the application
10 ↓
11localhost:3000 or localhost:8080
12 ↓
13Next.js / Node.js
14 ↓
15ResponseSSL protects the connection between the browser and Nginx. Nginx then communicates with the application locally. PM2 keeps the Node.js applications alive. DNS determines which server receives the request.
The Biggest Lesson
Hosting a website on a VPS is not really one task. It is several small systems connected together: Linux, processes, networking, DNS, Nginx, applications, SSL, firewall rules, and monitoring.
The trick is not memorizing every command. The trick is knowing which layer to inspect when something goes wrong.
"Application first. Then Nginx. Then DNS. Then SSL. Debug one layer at a time."
Final Thoughts
This setup gives me a simple and reusable production architecture: applications run privately on the VPS, PM2 manages the processes, Nginx acts as the reverse proxy, DNS connects the domains to the server, and Let's Encrypt provides HTTPS.
I have forgotten these steps before, so this article is partly a tutorial and partly a note to my future self. The next time I provision a VPS, I want to be able to come back here, follow the checklist, and avoid searching through old terminal history for commands I already knew.
Quick Reference
- Application check: curl http://127.0.0.1:3000
- Port check: ss -lntp
- Nginx test: nginx -t
- Nginx reload: systemctl reload nginx
- PM2 status: pm2 status
- PM2 logs: pm2 logs
- DNS check: dig example.com +short
- SSL check: certbot certificates
- SSL renewal test: certbot renew --dry-run
- Nginx error logs: tail -f /var/log/nginx/error.log

