
Building Your Portfolio Experience
Loading Tariqul Islam's projects...
Loading Tariqul Islam's projects...
Host your Next.js 14+ App Router project on Hostinger VPS with NGINX, PM2, and HTTPS. Secure and production-ready.
Hostinger VPS (Ubuntu 22.04+)
Domain (e.g. domain-name.com
)
GitHub repo with your Next.js project
Node.js v20+ and NGINX installed
ssh root@your-vps-ip
sudo apt update && sudo apt upgrade -y
# Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Nginx
sudo apt install nginx -y
sudo systemctl enable nginx
sudo service nginx status
# PM2
npm install -g pm2
pm2 startup
# Git
sudo apt install git -y
# Certbot
sudo apt install python3-certbot-nginx -y
# Firewall
sudo ufw enable
sudo ufw allow 'Nginx Full'
sudo ufw allow OpenSSH
At your domain provider, configure A/AAAA
records:
Type | Name | Value |
---|---|---|
A | @ | VPS IPv4 |
A | www | VPS IPv4 |
AAAA | @ | VPS IPv6 |
AAAA | www | VPS IPv6 |
Note: IPv6 (AAAA
records) is optional — only add them if your VPS provider supports and assigns an IPv6 address.
mkdir -p ~/apps && cd ~/apps
git clone git@github.com:yourusername/your-next-app.git
cd your-next-app
If private repo:
ssh-keygen -t ed25519 -C "your_email@example.com"
cat ~/.ssh/id_ed25519.pub
Add this key to GitHub > Settings > Deploy Keys.
Set environment variables:
nano .env
Install and build:
npm install
npm run build
Create ecosystem.config.js
:
module.exports = {
apps: [
{
name: 'natural-sefa',
script: 'npm start',
env: {
NODE_ENV: 'production',
},
},
],
};
package.json
(optional improvement):
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 3000",
"lint": "next lint"
}
Start and save:
pm2 start ecosystem.config.js
pm2 save
pm2 status
sudo nano /etc/nginx/sites-available/domain-name.com
Paste config:
server {
listen 80;
server_name domain-name.com www.domain-name.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;
}
}
Enable and test:
sudo ln -s /etc/nginx/sites-available/domain-name.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
sudo apt install python3-certbot-nginx -y
sudo certbot --nginx -d domain-name.com -d www.domain-name.com
# Reload and verify
sudo nginx -t
sudo systemctl reload nginx
# Auto-renew
sudo systemctl enable certbot.timer
sudo certbot renew --dry-run
cd ~/apps/your-next-app
git pull origin main
npm install
npm run build
pm2 reload next-app
Next.js app runs on PM2
Served via NGINX reverse proxy
HTTPS enabled with Certbot
🎉 Congratulations on a secure, production-ready deployment!