Linux
One-time server setup
# Ubuntu / Debian
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs nginx
# RHEL / CentOS / Fedora
curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
sudo dnf install -y nodejs nginxDeploy
npm --prefix web ci && npm --prefix web run build/opt/my-app/ ├── server.js ├── package.json ├── node_modules/ ├── .next/server/ ├── .next/static/ ← from web/.next/static/ ├── public/ ← from web/public/ └── .env ← create this on the serversudo chown -R www-data:www-data /opt/my-app[Unit] Description=My App After=network.target [Service] Type=simple User=www-data WorkingDirectory=/opt/my-app EnvironmentFile=/opt/my-app/.env Environment=NODE_ENV=production Environment=PORT=3000 Environment=HOSTNAME=127.0.0.1 ExecStart=/usr/bin/node server.js Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.targetsudo systemctl daemon-reload sudo systemctl enable --now my-app sudo systemctl status my-app sudo journalctl -u my-app -fserver { listen 80; server_name app.your-domain.com; client_max_body_size 20M; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }sudo ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled/sudo nginx -t && sudo systemctl reload nginx# Debian / Ubuntu sudo apt install -y certbot python3-certbot-nginx # RHEL / Fedora sudo dnf install -y certbot python3-certbot-nginx sudo certbot --nginx -d app.your-domain.com
Verify
Last updated
Was this helpful?