我的系统上运行着许多不同的服务器,它们都在各自的端口上运行安全连接,等等。50001,50002,50003...
所有这些都可以直接从 https://domain1.com:50001 访问...
现在,我不仅要限制端口数量,还要更改域等等。
https://domain1.com:50001 <- https://srv1.domain2.com:443
https://domain1.com:50002 <- https://srv2.domain2.com:443
https://domain1.com:50003 <- https://srv3.domain2.com:443
所有这些服务器都运行单独的 nodejs 实例。
现在我想构建一个代理而不是重定向它,我选择了 nodejs,因为我们所做的一切都在 nodejs 中。
我现在拥有的:
var app = require('express')();
var options = {
key : fs.readFileSync(CONFIG.sslKey).toString(),
cert : fs.readFileSync(CONFIG.sslCertificate).toString(),
ca : fs.readFileSync(CONFIG.sslCA).toString()
};
var http = require('https').Server(options,app);
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({
ssl: {
key : fs.readFileSync(CONFIGsecure.sslKey).toString(),
cert : fs.readFileSync(CONFIGsecure.sslCertificate).toString(),
ca : fs.readFileSync(CONFIGsecure.sslCA).toString()
},
secure: true
});
var handleRequests = function(req, res){
proxyTo = "https://domain1.com:50001"; <= some logic chooses this based on req.headers.host
proxy.web(req, res, { target: proxyTo });
};
app.get('/*', handleRequests );
app.post('/*', handleRequests );
app.put('/*', handleRequests );
app.delete('/*', handleRequests );
http.listen(443, function(){});
好的,这实际上工作得很好,一切都在浏览器中应该去的地方进行,在使用 jquery ajax 的 cordova 应用程序中,一切也工作得很好。 但是如果我使用
FileTransfer().download(...)
我收到错误代码 3(连接错误)。
如果我直接连接到 https://domain1.com:50001 (直接)该应用程序有效,但如果我连接到 https://srv1.domain2.com:443 (代理)该应用程序不起作用。
所有证书均有效,*.domain2.com 上的通配符证书和 domain1.com 上的单一证书。
终端服务器安装了 domain1.com 证书,代理安装了 *.domain2.com 通配符证书。
知道如何正确设置代理服务器吗?该系统是 Windows Server 2012 R2,如果需要,我愿意使用真正的代理。但是,如果解决方案尽可能简单,那就太好了。
我在这里尝试了示例二:
http://blog.nodejitsu.com/http-proxy-intro/
然而这是同样的问题,它只是 GET 请求。
我也试过在终端服务器上禁用 https,这样只有代理是安全的,但是,结果相同......
谢谢...
最佳答案
好的,所以我发现了问题,出于某种原因,req.headers.host 字符串也包含 :port,我只是打开了地址。现在一切正常。
关于node.js - 我如何正确地将 https 请求代理到 cordova 的另一个 https 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30903194/