I am trying to deploy a full next js app in Cyberpanel
So i am trying to deploy a next js app to CyberPanel, and after following the only documentation they have on this (https://community.cyberpanel.net/t/how-to-host-nextjs-app-on-cyberpanel/44403/2) it did not work, the webiste is still showing me the 404 page, while I'm running the app (using pm2). The only thing i didnt do is that a ran it on the default port (3000).
I've tried so many things and here is the only way that worked for me.
1. Create the handler
2. Redirect the requests
(from "http://127.0.0.1:<CUSTOM_PORT>" to the domain/sub-domain)
3. Allow the port to be used
I don't know if this is the case for everyone, but for me it only worked after I've done this. Try not doing it, if it doesn't work come back to it.
By default, the port is not allowed to be used.
Access your server by SSH and execute this command:
4. Start your app
Now go to the SSH and start your app on the custom port that we have set.
(In NextJS, you can either change the start script in package.json to
next start -p <PORT>
, meaningnext start -p 11300
and then run it normally withnpm start
, or you can run directy the commandnpm start -- -p 11300
).Run it normally with npm to test if everything is working fine.
Then you can start it with pm2 with
pm2 start "npm start -- -p 11300"
.PS: This works for any Nodejs app not only NextJS.
I hope you find this helpful.