Node.js HTTPS 代理服务器不工作

标签 node.js http https proxy

我想为 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.js HTTPS 代理服务器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16201591/

相关文章:

http - url get format pattern like 1 _*1 是什么意思

node.js - 如何使用node js实时改变内容?

javascript - 为什么javascript不等待和forEach并执行下一行

angular - 如果使用 RJXS 运算符从 http.get Angular 收到空结果,则重试查询

php - 从 HTTP 自动切换到 HTTPS 的最佳实践是什么

http - 我的浏览器如何将我的 http 请求转换为 https?

iOS 错误代码=-1003 “A server with the specified hostname could not be found.”

node.js - Node HTTPS - 从 process.env 读取密码时 mac 验证失败

javascript - 服务器从 Node 启动时如何运行 grunt?

node.js - 我的 async/await 函数未在 AWS Lambda 中等待。我缺少什么?