Next Js page hosted in cloudways server showing 404 error

379 Views Asked by At

We have hosted next JS app in Cloudways Linode server via pm2. The page is working properly in localhost but showing 404 error in server. The screenshot of the page is as below: enter image description here

The .htacess file is as below:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)?$ http://127.0.0.1:3002/$1 [P,L]

The package json is as below:

{
  "name": "sb",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev -p 3002",
    "build": "next build",
    "start": "next start -p 3002",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "13.0.0",
    "react": "18.2.0",
    "react-dom": "18.2.0"
  },
  "devDependencies": {
    "eslint": "8.26.0",
    "eslint-config-next": "13.0.0"
  }
}

Kindly let us know what changes has to be done to make next JS app show index.js page

We tried npm export, changing .htaccess file and changing port but it is still showing 404 error. I also tried creating test.js page inside root folder and opening in browser it is running properly. But next JS index page not showing.

1

There are 1 best solutions below

2
ket-c On

I found solution that worked for me (2023-02-15) I'm also using nextjs on cloudways

Edit your .htaccess to

DirectoryIndex disabled
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:3002/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:3002/$1 [P,L]