How should I organize multiple Express servers on the same system?

前端 未结 2 1488
说谎
说谎 2020-12-07 07:25

I\'m using one server to host multiple Node.js web apps, which are distributed across multiple domains. My current practice is to run an Express server for each app on a dif

2条回答
  •  眼角桃花
    2020-12-07 08:09

    Since Express uses Connect, I'm pretty sure you can use Connect's virtual host middleware. It operates similar to other vhost modules on other products. I don't have multiple domains to test and show you proper code, but I would think it's something like this:

    express.createServer()
    .use(express.vhost('hostname1.com', require('/path/to/hostname1').app)
    .use(express.vhost('hostname2.com', require('/path/to/hostname2').app)
    .listen(80)
    

    If you get to the point where one Express server isn't enough, then look into using the Node.Cluster from the API. If that also isn't enough, then the current practice is to put a asnyc reverse proxy such as Nginx in front of your Express servers and point the proxies to your Express servers.

提交回复
热议问题