[英]2 node js + express applications sharing https port 443?
I have an ec2 instance where I am hosting a node js application ( NodeJS1
). 我有一个EC2实例,在其中托管节点js应用程序( NodeJS1
)。 I made a alternate version of the node js application ( NodeJS2
). 我制作了Node js应用程序的替代版本( NodeJS2
)。
I have registered a single domain for the ec2 instance. 我已经为ec2实例注册了一个域。
I also have ec2 security groups setup so that https uses 443 - There seems to be no way to tell ec2 I'd like https on a custom port. 我还设置了ec2安全组,以便https使用443- 似乎没有办法在自定义端口上告诉ec2我想要https。
Since the only possible https port is 443 is there any way I can have both nodejs applications share this port? 由于唯一可能的https端口是443,有什么办法可以让两个nodejs应用程序共享该端口吗?
EDIT 编辑
I should also mention I am using express for my node js app. 我还应该提到我正在为节点js应用程序使用express。 I am currently starting my app like this: 我目前正在这样启动我的应用程序:
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)
});
ANOTHER UPDATE 另一个更新
I am now trying this: 我现在正在尝试:
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...');
});
When I run it i get the following error: 当我运行它时,出现以下错误:
/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)
I searched for this error and it looks like this method is outdated (not supported anymore) how can I get this behavior? 我搜索了此错误,看来此方法已过时(不再受支持),我该如何获得此行为?
You could technically run them as two separate apps listening on other ports and then utilize the npm package http-proxy . 从技术上讲,您可以将它们作为两个单独的应用程序在其他端口上侦听来运行,然后使用npm软件包http-proxy 。 Using http-proxy, you could serve everything on 443, depending on the requested URI. 使用http-proxy,您可以在443上提供所有服务,具体取决于所请求的URI。
For example: 例如:
router: {
'example.com/nodejs1': 'localhost:4000',
'example.com/nodejs2': 'localhost:4001',
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.