我有一个绑定了单个IP的linux服务器。我想在此IP上的此服务器上托管多个Node.js站点,每个站点(显然)都有一个唯一的域或子域。我要他们都在80号港口。
要执行此操作,我有哪些选择?
一个显而易见的解决方案似乎是让所有的域名都由一个node.js web应用程序服务,该应用程序充当代理,并通过唯一端口运行的其他node.js应用程序。
发布于 2013-10-09 02:54:05
嗯..。为什么您认为nodejs应该充当代理。我建议运行几个节点应用程序来监听不同的端口。然后使用nginx将请求转发到正确的端口。如果使用单个nodejs,也会出现单点故障。如果这个应用程序崩溃,那么所有的网站都会瘫痪。
发布于 2014-06-24 00:50:55
我有一个在网站上使用的API,下面是我的配置。我也有它与SSL和GZIP,如果有人需要它,只需评论我。
var http = require('http'),
httpProxy = require('http-proxy');
var proxy_web = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 8080
}
});
var proxy_api = new httpProxy.createProxyServer({
target: {
host: 'localhost',
port: 8081
}
});
http.createServer(function(req, res) {
if (req.headers.host === 'http://www.domain.com') {
proxy_web.proxyRequest(req, res);
proxy_web.on('error', function(err, req, res) {
if (err) console.log(err);
res.writeHead(500);
res.end('Oops, something went very wrong...');
});
} else if (req.headers.host === 'http://api.domain.com') {
proxy_api.proxyRequest(req, res);
proxy_api.on('error', function(err, req, res) {
if (err) console.log(err);
res.writeHead(500);
res.end('Oops, something went very wrong...');
});
}
}).listen(80);
发布于 2013-10-09 01:48:03
使用nginx作为反向代理。
http://www.nginxtips.com/how-to-setup-nginx-as-proxy-for-nodejs/
Nginx在缓存、静态文件处理、ssl和负载均衡等方面为您的应用程序带来了一系列好处。
https://stackoverflow.com/questions/19254583
复制相似问题