🚀 How to Deploy a Next.js SSR App on MilesWeb VPS (AlmaLinux 8.10)
If you're building a Next.js SSR (Server-Side Rendering) app and want to host it on your MilesWeb VPS with AlmaLinux 8.10, this guide is all you need. Follow these clear steps to get your project live and production-ready.
🛠️ Prerequisites
- VPS with AlmaLinux 8.10 (MilesWeb)
- Root or
sudo
access to the server - Your Next.js project (with
app/page.js
structure) - Domain (optional but recommended)
🔐 Step 1: Connect to Your Server
ssh root@your-server-ip
Update your system:
dnf update -y
📦 Step 2: Install Node.js and Git
Install Node.js LTS (e.g., v18):curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -
dnf install -y nodejs
Check versions:
node -v
npm -v
Install Git if needed:
dnf install git -y
📁 Step 3: Upload or Clone Your Project
Option 1: Clone from GitHubcd /var/www
git clone https://github.com/your-repo.git my-next-app
cd my-next-app
Option 2: Upload from Your Laptop (via SCP)
scp -r /path/to/your/project root@your-server-ip:/var/www/my-next-app
⚙️ Step 4: Install & Build Your App
Go to the project folder:cd /var/www/my-next-app
Install dependencies:
npm install
Build the Next.js app:
npm run build
Start it (for testing):
npm start
🔁 Step 5: Use PM2 to Keep It Running
Install PM2:npm install -g pm2
Start the app with PM2:
pm2 start npm --name "my-next-app" -- start
pm2 save
pm2 startup
🌐 Step 6: Set Up Nginx Reverse Proxy
Install Nginx:dnf install nginx -y
systemctl enable nginx
systemctl start nginx
Create Nginx config:
nano /etc/nginx/conf.d/my-next-app.conf
Paste this:
server {
listen 80;
server_name your-domain.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;
}
}
Test and reload:
nginx -t
systemctl restart nginx
🔒 Step 7: Add Free SSL (Let's Encrypt)
Install Certbot:
dnf install epel-release -y
dnf install certbot python3-certbot-nginx -y
Issue a certificate:
certbot --nginx -d your-domain.com
Auto-renew:
echo "0 0 * * * root certbot renew --quiet" >> /etc/crontab
✅ Your Next.js SSR App is Live!
You can now visit your domain and enjoy your deployed Next.js app running smoothly on your MilesWeb VPS with AlmaLinux 8.10.
💡 Tips & Extras
- Use
.env.production
for environment variables - Use
pm2 logs
to monitor your app - Block unused ports with a firewall
Need help? Drop your questions in the comments or contact your server provider. Happy deploying! 🚀
Comments
Post a Comment