CyberPanel Community

ClosedHow to run multiple subdomain Nodejs apps with SSL

jo
josephgodwinke #1

I want to run multiple nodejs apps (e.g. www.api.example.net/v1, www.api.example.net/v2) on several subdomains all using SSL - https://www.api.example.net/v1, https://www.api.example.net/v1.

Note: Only one app can run on port 3000 and automatically proxy to port 80 via context

7 replies
sh
shoaibkk #2

Didn’t get it what actually is your question can you please share more details

lu
luckyrajpurohit #5

You can run same as parent domain with other node port like 3002

jo
josephgodwinke #6

I tried and am getting “Not Found” error.

the vHost conf of parent domain:

context / {
  type                    appserver
  location                /home/mgxty.com/public_html
  binPath                 /usr/bin/node
  appType                 node
  maxConns                100
 
  rewrite  {
 
  }
  addDefaultCharset       off
}

and the subdomain customer12.mgxty.com:

context / {
  type                    appserver
  location               /home/mgxty.com/customer1
  binPath                 /usr/bin/node
  appType                 node
  maxConns                100
 
  rewrite  {
 
  }
  addDefaultCharset       off
}

Both NodeJS apps are completely the same. I just changed ports (3000 and 3002) and rebooted the server.

jo
josephgodwinke #8

Am sorry i you already gave me the answer. The “Not Found” issue is a NodeJS issue, I dont get how I didn’t catch that, which i got it fixed. Thank you

Scenario 1: NodeJS app running on mgxty.com and you need subdomain/child domain - customer1.mgxty.com just change port as @luckyrajpurohit said. This way you can get SSL running on both domains.

Scenario 2: NodeJS app running on mgxty.com and you need to run another NodeJS app on mgxty.com/api. Change port as @luckyrajpurohit said. This way you don’t get SSL running on both domains.

You don’t need PM2 for this but it makes it ideal to view logs of every NodeJS app and keep them alive.

jo
josephgodwinke #9

This is not needed because cyberpanel does this for you by proxing with context for NodeJS and rewrite rules for php frameworks

Sign in to reply