首页 > 解决方案 > 带有 https 目标的 Http 代理

问题描述

我正在尝试使用库在 NodeJs 中创建自己的代理服务器,node-http-proxy问题是我想创建一个 http 代理服务器,它可以将请求转发到 https 目标(例如https://google.com)。

我知道这是可能的,因为已经有一个库可以做到这一点:proxy-chain

当我尝试使用以下命令请求 https 目标时,node-http-proxy出现错误:ERR_EMPTY_RESPONSE.

它还在文档中声明我需要添加 PKCS12 客户端证书,但proxy-chain不这样做。

有没有办法可以proxy-chain用图书馆复制node-http-proxy图书馆?

这是我目前的代码:

var proxy = httpProxy.createProxyServer({});

var server = http.createServer(function(req, res) {
  // You can define here your custom logic to handle the request
  // and then proxy the request.
  proxy.web(req, res, {
    target: {
        hostname: 'github.com',
        port: 433,
        protocol: 'https',
    },
    secure: false,
    changeOrigin: true
  });
});

console.log("listening on port 5050")
server.listen(5050);

标签: node.jsproxynode-http-proxy

解决方案


推荐阅读