Next.js 14 introduces Partial Prerendering, improved Server Actions, and a stable Turbopack bundler. This guide creates and deploys a Next.js 14 application on Ubuntu 24.04 LTS with PM2 and Nginx.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • Node.js 20 LTS installed
  • PM2 installed
  • Nginx installed

Step 1 – Create a New Next.js 14 Application

Use the official create-next-app scaffolding tool:

npx create-next-app@14 /var/www/mynextapp --typescript --eslint --tailwind --app

Step 2 – Build the Application

Produce an optimised production build:

cd /var/www/mynextapp
npm run build

Step 3 – Start with PM2

Launch the production server:

pm2 start npm --name nextapp -- start
pm2 save

Step 4 – Enable PM2 on Boot

Auto-start on server restart:

pm2 startup
pm2 save

Step 5 – Configure Nginx as a Reverse Proxy

Create an Nginx server block:

sudo nano /etc/nginx/sites-available/mynextapp

Add:

server {
    listen 80;
    server_name next.example.com;
    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;
    }
}

Enable and reload:

sudo ln -s /etc/nginx/sites-available/mynextapp /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Step 6 – Add SSL

Enable HTTPS with Certbot:

sudo certbot --nginx -d next.example.com

Step 7 – Set Environment Variables

Create a production environment file:

nano /var/www/mynextapp/.env.local

Add your environment-specific variables, then rebuild:

npm run build && pm2 restart nextapp

Conclusion

Next.js 14 is now running on Ubuntu 24.04 LTS. The App Router with React Server Components enables high-performance rendering with minimal client-side JavaScript.