Launch pricingNo GST added. What you see is what you pay.

Deploy apps · 20 min

Deploy a Next.js app

Build and run a Next.js app in production, behind Nginx.

This runs Next.js with its built-in production server, kept alive by PM2, with Nginx in front for your domain and HTTPS.

1. Install Node.js, PM2 and Nginx

bash
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs git nginx
sudo npm install -g pm2

2. Build your app

bash
cd /opt && sudo git clone https://github.com/you/your-next-app.git
sudo chown -R $USER:$USER your-next-app && cd your-next-app
npm ci
npm run build

Put your environment variables in .env.production before building if your app needs them.

3. Run it with PM2

bash
pm2 start npm --name next-app -- start -- -p 3000
pm2 save && pm2 startup

4. Put Nginx in front

Create a site config (replace example.com):

bash
sudo tee /etc/nginx/sites-available/next-app > /dev/null <<'EOF'
server {
    listen 80;
    server_name example.com www.example.com;
    location / {
        proxy_pass http://127.0.0.1:3000;
        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";
    }
}
EOF
sudo ln -s /etc/nginx/sites-available/next-app /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

5. Domain and HTTPS

Point your domain to the server, open ports 80 and 443 in the firewall, then add free HTTPS.

Deploying updates

bash
cd /opt/your-next-app && git pull && npm ci && npm run build && pm2 restart next-app

Stuck? Contact us or open a support ticket from your panel.