[英]2 node js + express applications sharing https port 443?
我有一个EC2实例,在其中托管节点js应用程序( NodeJS1
)。 我制作了Node js应用程序的替代版本( NodeJS2
)。
我已经为ec2实例注册了一个域。
我还设置了ec2安全组,以便https使用443- 似乎没有办法在自定义端口上告诉ec2我想要https。
由于唯一可能的https端口是443,有什么办法可以让两个nodejs应用程序共享该端口吗?
编辑
我还应该提到我正在为节点js应用程序使用express。 我目前正在这样启动我的应用程序:
var app = express();
app.set('port', process.env.PORT || 3030);
fs = require('fs')
var sslOptions = {
key: fs.readFileSync('./mykey.key'),
cert: fs.readFileSync('./mycert.crt'),
};
https = require('https').createServer(sslOptions, app);
var server = https.listen(app.get('port'), function (err) {
if (err) throw err;
console.log('listening on ' + server.address().port)
});
另一个更新
我现在正在尝试:
var httpProxy = require('http-proxy');
var fs = require('fs');
var proxyTable = {};
proxyTable['example.com/baz'] = 'http://localhost:3030';
proxyTable['example.com/buz'] = 'http://localhost:3031';
var httpOptions = {
router: proxyTable
};
var httpsOptions = {
router: proxyTable,
ssl: {
key: fs.readFileSync('./mykey.key', 'utf8'),
cert: fs.readFileSync('./mycert.crt','utf8')}
};
httpProxy.createServer(httpsOptions).listen(443, function(err){
if (err) throw err;
console.log('proxy listening...');
});
当我运行它时,出现以下错误:
/home/ec2-user/MacaronicWebApp/node_modules/http-proxy/lib/http-proxy/index.js:119
throw err;
^
Error: Must provide a proper URL as target
at ProxyServer.<anonymous> (/home/ec2-user/MacaronicWebApp/node_modules/http-proxy/lib/http-proxy/index.js:68:35)
at Server.closure (/home/ec2-user/MacaronicWebApp/node_modules/http-proxy/lib/http-proxy/index.js:125:43)
我搜索了此错误,看来此方法已过时(不再受支持),我该如何获得此行为?
从技术上讲,您可以将它们作为两个单独的应用程序在其他端口上侦听来运行,然后使用npm软件包http-proxy 。 使用http-proxy,您可以在443上提供所有服务,具体取决于所请求的URI。
例如:
router: {
'example.com/nodejs1': 'localhost:4000',
'example.com/nodejs2': 'localhost:4001',
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.