简体   繁体   中英

How to deploy node.js application in cyberpanel?

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?

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

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.

文件夹结构

  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

在此处输入图像描述

  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.

Thank you

Not able to comment due to low reputation ? message me on twitter - @Sawrubgupta

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM