简体   繁体   中英

Hosting multiple node app.js in a sub-domain

Is there a way i can host multiple nodejs app.js on single port for multiple tenancy? Either in Docker or in vps

Each tenant can only access his/her folder containing his/her app.js.

I wanted to create a package inside node_module and create multiple customers workspace folders inside the package and be importing the matched subdomain hostname request with customer workspace from main nodejs and whereby activating wild subdomain like *.mainDomain.com But i think this might look silly because customer workspace inside node_module might not look safe

You cannot use the same port for multiple node.js applications but you can look at leveraging nginx. You can configure nginx to listen on one port for multiple domain names and then redirect requests to the IP and port of the respective node.js application.

This link might help you to achieve it: https://serverfault.com/questions/536576/nginx-how-do-i-forward-a-http-request-to-another-port

Is there a way i can host multiple nodejs app.js on single port for multiple tenancy? Either in Docker or in vps

You cannot have more than one applications listening on the same port on a single machine. If you want to route traffic from a single port to more than one applications or dockers you would need an application to listen on a port an decide where to route the incoming request every time. Each of the rest of the application would have to listen to a different port of the host machine.

As for the second part of your question, I think it quite clear what you are trying to do. What is the main nodejs , and why would you create a folder inside node_modules ?

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