CyberPanel Community

How to run the port 3000, ProxyPass and ProxyPassReverse?

CR
Carlos Reyes #1

Help, I have tried to add this without success. Someone could tell me how to do it correctly, I come from cpanel. I’m a little disoriented here.Thank you.

3 replies
jo
josephgodwinke #2

Hello @oswaldocfr

Putting it simply you are trying to run a nodejs app (not on docker) using cyberpanel and monitoring it using pm2 ?

CR
Carlos Reyes #3

Yes, I upload the files to the web in cyberpanel and run with the command “yarn next start”, But according to the image I must add those lines in the equivalent of httpd.conf (cpanel) in cyberpanel.

jo
josephgodwinke #4

Yes to deploy nodejs app on cyberpanel you need to upload the build files to your document root and create a proxy with context but ina different way:

Go to List Websites → mynodejsapp.com → vHost Configurations

context / {
  type                    appserver
  location                /home/mynodejsapp.com/public_html/build
  binPath                 /usr/bin/node
  startupFile              server.js
  appType                 node
  maxConns                100
 
  rewrite  {
 
  }
  addDefaultCharset       off
}

change startupFile to the file that will be loaded. If its index.js just remove that directive.

I would assume its a nextjs app so you should have run next build. I would assume this would end up in a dist folder. Upload this folder in your expressjs app at your document root

|-- dist # put all build files in here 
|-- node_modules
|-- index.js # this is file from https://community.cyberpanel.net/t/setup-express-js-application-on-cyberpanel-openlitespeed/30641#step-3-setup-basic-expressjs-application-3
|-- package.json
|-- package-lock.json
|-- yarn.lock

If its just an SSG you would use this index.js instead:

const express = require('express');
const path = require('path');
const app = express();

app.use(express.static(path.join(__dirname, 'dist')));

app.get('/', function (req, res) {
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});

app.listen(3000);

Cause certianly your build/dist looks like this

|-- vercel.svg
|-- index.html
etc

Then using pm2 add the new app

$ npm install pm2 -g
# add app to pm2
$ pm2 start index.js --name "nextjs-app" --watch # index.js is the express file
# daemonize your app
$ pm2 startup && pm2 save
# to see all your node apps
$ pm2 list
# Display all apps logs in realtime
$ pm2 monit

Further reading

https://openlitespeed.org/kb/reverse-proxy-basics/

Sign in to reply