Деплой Next.js

Сборка, запуск через PM2 и HTTPS через Nginx + Certbot

1. Тариф

Задача Next.js / фронтенд: от 2 vCPU и 4 ГБ RAM — next build на 2 ГБ часто уходит в своп.

2. Node.js и проект

curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt install -y nodejs git
git clone https://github.com/you/site.git /opt/site && cd /opt/site
npm ci && npm run build

3. Запуск через PM2

npm install -g pm2
pm2 start npm --name site -- start -- -p 3000
pm2 save && pm2 startup

4. Nginx и HTTPS

Направьте A-запись домена на IP сервера, затем:

apt install -y nginx certbot python3-certbot-nginx
cat >/etc/nginx/sites-available/site <<'NGX'
server {
  server_name example.com;
  location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; }
}
NGX
ln -s /etc/nginx/sites-available/site /etc/nginx/sites-enabled/ && nginx -t && systemctl reload nginx
certbot --nginx -d example.com

Обновление сайта: git pull && npm ci && npm run build && pm2 restart site.

Обновлено