Posts

Showing posts from July, 2024

Deploy nextjs in nginx with PM2

Step by Step In next.config.mjs comment // output: 'export' $ npm run build  In next.config.mjs Uncomment // output: 'export' $ npm run build Move nextjs directory to /var/www/ in VPS without node_modules (It's Big files) $ npm i $ cd /etc/nginx/sites-available server {     listen 80;     server_name proj.consultechbd.com;  # Replace with your actual domain name     location / {         #root   /var/www/nextjs-paikari/out;         #index  index.html;         proxy_pass http://localhost:3000;         proxy_http_version 1.1;         proxy_set_header Upgrade $http_upgrade;         proxy_set_header Connection $connection_upgrade;         proxy_set_header Host $host;         proxy_cache_bypass $http_upgrade;     }     location /_next/static/ {         alias /var/www/nextjs-paikari/out/_next/static/;         #expires 1d;         access_log off;     }     location /static/ {         alias /var/www/nextjs-paikari/out/static/;         #expires 1d;         access_log off;