I'm trying to learn next.js and I'm really struggling working out how to deploy it on my VPS as I'm not used to running a site where there is no index.html. I've been trying to research it for the best part of a week and it's driving me a bit nuts!!
So, my VPS is with Centos 7, cyberpanel and openlitespeed. For testing purposes I'm just using the initial next.js build (i.e. what's first created). I copied over the files to the public_html folder of my site and ran 'npm build'. If I run 'npm start' I can see the 'site' on my-domain-name:3000. But I can't figure out how to get this to run on just my-domain-name. All the information I find either seems to be about deploying on various services (Vercel, digital ocean etc) or in other ways unrelated to just setting it up on a VPS
The closest lead I have so far is that in OpenLiteSpeed I need to create an App Server 'context' for the virtual host for my site (CyberPanel auto-created this) and have entered the following settings:
- URI: /
- Location: /home/$VH_NAME/public_html
- Binary Path: /usr/bin/node (not sure if this is right but there is this file on my server level)
- Application Type: Node
- Startup File: server.js
The startup file is the basic one shown at https://nextjs.org/docs/advanced-features/custom-server. I also tried updating the scripts with the following:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
Additionally I tried opening the port up in my firewall (CFS)
I still can't seem to figure out how I'm supposed to be getting my VPS to run this site without using the port number or how to keep it running when I terminate my session in VS Code. I feel that I'm really misunderstanding how to set up OpenLiteSpeed as a reverse proxy and I'm also a little worried that if I keep testing random things out I'm likely to damage something.
This is probably modern web dev 101 but I'm really over my head here and not sure where to look for the answers. If someone has a moment would you be able to point me in the right direction? Happy to provide any other information about my set-up necessary...
Thanks in advance