How to deploy node.js application in cyberpanel?

9.8k views Asked by At

I have my application developed in node.js, and I have cyberpanel installed on my server. I have seen many examples of how to deploy a node application in cyberpanel, but I have doubts about how to view it from the browser.

So far I have the following configuration in vHost:

context / {
    type                    appserver
    location                /FOLDER/FOLDER/PROJECT_FOLDER/dist
    binPath                 /usr/bin/node
    startupFile             index.js
    appType                 node
    maxConns                100
}

My application runs perfectly on port 3000 when I run it by console, but I need to list it on port 80 with cyberpanel.

Does anyone have an idea how to do it?

3

There are 3 answers

0
Indraprastha Design On

try the following steps. Essentially, the error lies in selecting the root document folder and allowing access to the application.

  1. Create a Website using the normal CyperPanel menu. [https://cyberpanel.net/docs/2-creating-website/]

  2. Upload your Node.Js files into the public_html folder of the website.

  3. Enter the Open Lite Speed panel via port :7080 (you would need to enable the port on the firewall)

  4. Navigate to VH Hosts > Your Domain > Context

  5. Select App Server, for location using $VH ROOT instead of the hardcoded path worked.

Additionally, don't forget to enable the site on access control via allowing all IPs (*).

        context / {
  type                    appserver
  location                $VH_ROOT/public_html/
  binPath                 /usr/bin/node
  appType                 node
  startupFile             server.js  //this is the name of your 
  appserverEnv            1
  maxConns                100

  accessControl  {
    allow                 *
  }

  rewrite  {

  }
  ad
0
Julio César Benavente On

I got the answer from here: https://community.cyberpanel.net/t/proxy-preserve-host/14733

Your application should be running in port, something like this 127.0.0.1:3000.

What you can do is to go to Websites > List of websites > Pick your website > Manage option. There you will find the vHost Conf section, there you should paste this:

extprocessor appname {
  type                    proxy
  address                 127.0.0.1:your_app_port (3000 for this example)
  maxConns                100
  pcKeepAliveTimeout      60
  initTimeout             60
  retryTimeout            0
  respBuffer              0
}

And the last step would be pasting the following in the Rewrite rules section

RewriteEngine On
RewriteRule ^(.*)$ HTTP://appname/$1 [P]

Best of luck!

4
SAURABH On

See I am going to answer point to point to the question

First of all cyberpanel by default only takes app.js file as its core file to run the application. Second, How to change that default file pointing ?

     context / {
  type                    appserver 
  startupFile             index.js // **NAME OF YOUR STARTUP FILE**
  location                /home/PROJECT_FOLDER/public_html/dist 
  binPath                 /usr/bin/node
  appType                 node 
  appserverEnv            1
  maxConns                100

  accessControl  {
    allow                 *
  }

  rewrite  {

  }
  ad        
     

location /FOLDER/FOLDER/PROJECT_FOLDER/dist Note :- Things, I want to mention about this location parameter is this is the location to the your startup file, you will get it via file manager, as you cannot run typescript code directly here, you have to convert it into javascript using tsc command and further target dist folder using location parameter in vconfig file

Now next question is how to run application outside console ?

  1. Create a website to deploy the project, use below link for reference click here
  2. Issuing SSL for website - link for reference
  3. This is my folder structure for deployment, simply zip all files and upload it on file manager of cyber panel, and extract out your files. You can see, I have dist folder which contains all javascript files and also have index.js, the main startup file.

folder structure

  1. Click on fix permissions on file manager.

  2. Go to Web terminal and install node modules. how ? on web terminal :- type cd .. and press enter. There you have to find out your project from directory, You can use ls command to get list of files and folder structure. mine directory was (after using cd ..) :- cd home/FOLDERNAME/public_html At last run your project through terminal, to check its working.

  3. Config your vhost config file, below is reference image

enter image description here

  1. File you have to add in vhost config, I also had provided you above.

  2. If you domain is setup correctly, you can view on api on your domain else you can click on preview button on cyber panel

Note :- Always Run code in terminal first to check its working.