Running multiple sites on node.js

前端 未结 1 1477
面向向阳花
面向向阳花 2021-02-04 17:26

I\'m planning to do three sites using node.js. I have got some common templates among the sites. Should I run all three sites on single node.js instance?

I\'m aware of

1条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 18:08

    I myself just had to do this exact same thing. What you want to do is use some sort of reverse proxy.

    The one I use is here: https://github.com/nodejitsu/node-http-proxy

    Simply install the proxy package: npm install http-proxy

    What I do is have the proxy running on the server on port 80. I set the DNS up on each domain to point to this server.

    Each application is running on the same server (im using screens).

    For example:

    MySiteApplication1 - 3001
    MySiteApplication2 - 3002
    MySiteApplication3 - 3003
    

    Then your proxy server file would look like this

    var httpProxy = require('http-proxy');
    
    var server = httpProxy.createServer({
       router: {
         'mysite1.com': 'localhost:3001',
         'mysite2.com': 'localhost:3002',
         'mysite3.com': 'localhost:3003'
       }
    });
    
    server.listen 80
    

    0 讨论(0)
提交回复
热议问题