Skip to content

Instantly share code, notes, and snippets.

@dirumahrafif
Last active September 10, 2025 16:42
Show Gist options
  • Select an option

  • Save dirumahrafif/73113f6c7c2b481bacbedeac1af0c4c7 to your computer and use it in GitHub Desktop.

Select an option

Save dirumahrafif/73113f6c7c2b481bacbedeac1af0c4c7 to your computer and use it in GitHub Desktop.
Jalankan NextJS di VPS

Jalankan NextJs di VPS

  • Di dalam project nextJs
npm install #instal dependencies
npm run build
npm start # coba di control + c akan tertutup
  • supaya bisa jalan terus install pm atau process manager
sudo npm install pm2@latest -g
  • jalankan prosesnya
pm2 start npm --name "nextjs-app" -- start
  • akses masih menggunakan port 3000

Akses Tanpa Port

  • instal nginx
sudo apt install nginx -y
  • Konfigurasi server block
sudo nano /etc/nginx/sites-available/nextjs
  • edit isi
server {
    listen 80;
    server_name _;

    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;
    }
}
  • aktifkan
sudo ln -s /etc/nginx/sites-available/nextjs /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment