DEV Community

SWAPNIL AHMMED SHISHIR
SWAPNIL AHMMED SHISHIR

Posted on

Biggner pm2, nginx, GitHub action setup dedicated server

👉 GitHub password allow করে না .

✅ Solution → SSH Key (BEST & STANDARD)

HTTPS use করা = beginner mistake 😄
Production server always uses SSH.


✅ STEP 1 — Generate SSH Key (Server)

Server এ run করো:

ssh-keygen -t ed25519 -C "server"
Enter fullscreen mode Exit fullscreen mode

Press Enter → Enter → Enter
(no password)

তারপর:

cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

Output copy করো.


✅ STEP 2 — Add SSH Key to GitHub

Go to:

👉 GitHub → Settings
👉 SSH and GPG Keys
👉 New SSH Key

Paste key.

Save.


✅ STEP 3 — Clone Again (IMPORTANT)

Now use SSH:

git clone git@github.com:url.git
Enter fullscreen mode Exit fullscreen mode

👉 DONE ✅
আর username/password চাইবে না.


🔥 STEP 4 — Install Node (If not installed)

Check:

node -v
Enter fullscreen mode Exit fullscreen mode

If missing:

👉 Install Node 20 (recommended)

VERY IMPORTANT:
Use NVM (never install Node globally on production)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

reload:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Install node:

nvm install 20
nvm use 20
Enter fullscreen mode Exit fullscreen mode

🔥 STEP 5 — Install PM2 (Production Manager)

PM2 keeps the app alive.

Install:

npm install -g pm2
Enter fullscreen mode Exit fullscreen mode

Check:

pm2 -v
Enter fullscreen mode Exit fullscreen mode

🔥 STEP 6 — First Build (Manual One Time)

Go project:

cd landing-page-katsana
Enter fullscreen mode Exit fullscreen mode

Install:

npm install
Enter fullscreen mode Exit fullscreen mode

Build:

npm run build
Enter fullscreen mode Exit fullscreen mode

Start:

pm2 start npm --name "demo" -- start
Enter fullscreen mode Exit fullscreen mode

Check:

pm2 list
Enter fullscreen mode Exit fullscreen mode

If running → perfect ✅

Auto start after reboot:

pm2 startup
pm2 save
Enter fullscreen mode Exit fullscreen mode

VERY IMPORTANT — don’t skip.


🔥 STEP 7 — Setup NGINX (Reverse Proxy)

Why?

👉 Port 3000 expose করা is dangerous
👉 Nginx handles domain + SSL + speed.

Install:

yum install nginx -y
Enter fullscreen mode Exit fullscreen mode

Start:

systemctl start nginx
systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

✅ Create Config

nano /etc/nginx/conf.d/fileName.conf
Enter fullscreen mode Exit fullscreen mode

Paste:

server {
    listen 80;
    server_name example.com.bd www.example.com.bd;

    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;
    }
}
Enter fullscreen mode Exit fullscreen mode

Save.

Test:

nginx -t
Enter fullscreen mode Exit fullscreen mode

Reload:

systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

👉 Now site LIVE 🎉


🔥 MOST IMPORTANT PART (AUTO DEPLOY)

Now আমরা automation করবো.

⭐ Best Method → GitHub Action + SSH Deploy

No FTP needed.
Real DevOps style.


✅ STEP 8 — Create GitHub Secrets

GitHub repo → Settings → Secrets → Actions

Create:

HOST = server ip
USERNAME = root
SSH_KEY = your private key
Enter fullscreen mode Exit fullscreen mode

To get the private key:

On your PC:

cat ~/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

Copy the full key.


✅ STEP 9 — GitHub Action (AUTO DEPLOY)

Create:

.github/workflows/deploy.yml
Enter fullscreen mode Exit fullscreen mode

Paste:

name: Deploy to Dedicated Server

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Deploy via SSH
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /home/katsan/landing-page/landing-page

            git pull origin main

            npm install

            npm run build

            pm2 restart katsan
Enter fullscreen mode Exit fullscreen mode

🔥 RESULT (Now Your Flow)

You push code:

git push origin main
Enter fullscreen mode Exit fullscreen mode

👇

GitHub Action runs
👇
SSH into the server
👇
git pull
👇
build
👇
PM2 restart

🔥 ZERO manual work.


⭐ PRO TIP (Senior Secret)

Use this instead of npm install:

npm ci
Enter fullscreen mode Exit fullscreen mode

👉 faster
👉 cleaner
👉 production safe


🚨 VERY IMPORTANT SECURITY WARNING

👉 NEVER use root for deployment long term.

Later create user:

deploy
Enter fullscreen mode Exit fullscreen mode

Give sudo.

More secure.


🔥 Architecture You Just Built

This is used by:

👉 SaaS companies
👉 production startups
👉 high traffic apps

You are no longer a beginner after this 😄


If you want — next level setup আমি তোমাকে দিতে পারি:

🔥 ZERO downtime deploy
🔥 Blue-green deployment
🔥 Docker setup
🔥 CI/CD pro pipeline
🔥 Auto SSL
🔥 Server hardening
🔥 Fail2ban
🔥 Redis cache
🔥 5x Next.js speed

Top comments (0)