将多个Node.js的web应用 [英] Combine multiple node.js web applications

查看:129
本文介绍了将多个Node.js的web应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出做到这一点的最好办法;基本上我有6个网站我要上网,但此刻,他们将不得不接零流量,以节省他们需要被部署在同一台服务器(理想情况下,我们将使用弹性魔豆从AWS)上的钱。

I'm trying to figure out the best way to accomplish this; essentially I have about 6 websites I have to get online but at the moment they will have next to zero traffic so to save money they need to be deployed on the same server (ideally we will be using Elastic BeanStalk from AWS).

有没有办法从根本上写的像正常的每个Web应用程序(使他们很容易被感动,并在将来的专用服务器),但有一个app.js适当的负荷节点应用根据URL的切入点?

Is there a way to essentially write each web application like normal (so they can easily be taken and moved to a dedicated server in the future) but have one app.js entry point that appropriate loads the node application depending on the URL?

显然,这是不理想,但我已经想到了几个方法可以做到这一点,但我想作为非哈克尽可能使网站可以很容易地以后移动。

Obviously this isn't ideal but and I've thought of a couple of ways to do this but I want to be as non-hacky as possible so the sites can easily be moved later.

推荐答案

使用连接的虚拟主机。 http://www.senchalabs.org/connect/vhost.html

Use connect vhost. http://www.senchalabs.org/connect/vhost.html

var express = require('express'),
    main = express();

main.use(express.vhost('*.site1.com', require('../site1')));
main.use(express.vhost('*.site2.com', require('../site2')));

main.listen(80);

../ SITE1 / index.js 可能是这样的:

var express = require('express'),
    app = express();

app.get('/', function(req, res) { res.send('Home Page'); });

module.exports = app;

这篇关于将多个Node.js的web应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆