Node.js tətbiqini VPS-də deploy etmək | Bilgi Bankası

Node.js tətbiqini VPS-də deploy etmək

Node.js tətbiqi - production-ready deployment

Node tətbiqi development-də node app.js ilə işləyir. Amma production fərqlidir: yenidən başlatma, multi-core istifadəsi, reverse proxy lazımdır.

1. Node və NPM quraşdırması

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash
sudo apt install nodejs -y
node -v && npm -v

2. Tətbiqi serverə yükləmək

cd /var/www
git clone https://github.com/user/myapp.git
cd myapp
npm install --production
cp .env.example .env  # konfiq

3. PM2 - proses meneceri

sudo npm install -g pm2
pm2 start app.js --name myapp -i max  # bütün CPU core-ları
pm2 save
pm2 startup  # boot-da avtomatik başla

Faydalı PM2 əmrləri:

pm2 list
pm2 logs myapp
pm2 restart myapp
pm2 stop myapp
pm2 monit  # real-time monitoring

4. Nginx reverse proxy

server {
    listen 80;
    server_name api.mysite.az;
    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_set_header X-Real-IP $remote_addr;
        proxy_cache_bypass $http_upgrade;
    }
}

5. SSL əlavə etmək

sudo certbot --nginx -d api.mysite.az

6. Avtomatik deploy (CI/CD)

GitHub webhook + skripti:

#!/bin/bash
cd /var/www/myapp
git pull
npm install --production
pm2 restart myapp

Logging və monitoring

pm2 install pm2-logrotate

Axtardığınız məlumatı tapa bilmirsiniz?

Bilgi bankasını ətraflı şəkildə incələmisiniz, amma ehtiyacınız olan məlumatı tapa bilmirsinizsə,

Bir dəstək sorğusu yaradın.
Faydalı oldumu?
Bildiriminiz için Teşekkür Ederiz.
Bunun için üzgünüz :( Daha iyisi için çalışacağız.
Daha önce oylama yaptınız.
(30 defa görüntülendi. / 0 kişi faydalı buldu.)