我想为 HTTPS
与 Node.js 的连接创建一个代理。我正在使用 http-proxy
图书馆,效果很好。我可以让 HTTP
代理完美地工作,但是当我尝试 HTTPS
时,对代理的请求只是超时。这是我的代码(node-http-proxy
proxy-https-to-https
示例的略微修改版本):
var http = require("http"),
https = require("https"),
httpProxy = require("http-proxy"),
fs = require('fs');
var httpsConfig = {
key: fs.readFileSync('./jackos2500-key.pem'),
cert: fs.readFileSync('./jackos2500-cert.crt'),
};
https.createServer(httpsConfig, function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('hello https\n');
res.end();
}).listen(8000);
httpProxy.createServer(8000, 'localhost', {
https: httpsConfig,
target: {
https: true,
rejectUnauthorized: false
}
}).listen(443);
这里是否有明显的遗漏或其他问题?
最佳答案
node-http-proxy 有一个 Unresolved 问题
https://github.com/nodejitsu/node-http-proxy/issues/454#issuecomment-25661401
关于Node.js HTTPS 代理服务器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16201591/