Nodejs HTTPS->HTTPS 代理

问题描述

我正在尝试设置一个 HTTPS 服务器,该服务器将请求代理到也强制执行 HTTPS 的更改目标。这是因为我想设置一个拦截 https 代理,终止 ssl,修改数据并将加密的修改发送到目标服务器(或通过响应向后发送)。

示例:

browser --> myHTTPSProxy(modify request) --> https://targethost.com --> myHTTPSProxy(modify response) --> browser

这是来自 node-http-proxy library 的任务的示例实现:

const https = require('https'),fs = require('fs'),colors = require('colors'),httpProxy = require('http-proxy'),httpsOpts = {
        key: fs.readFileSync('agent2-key.pem','utf8'),cert: fs.readFileSync('agent2-cert.pem','utf8')
    };

// Create DUMMY HTTPS SRV
https.createServer(httpsOpts,function (req,res) {
    res.writeHead(200,{ 'Content-Type': 'text/plain' });
    res.write('hello https\n');
    res.end();
}).listen(3000);

// PROXY
httpProxy.createServer({
    ssl: httpsOpts,target: 'https://localhost:3000',secure: false
}).listen(8080);

console.log('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8080'.yellow);
console.log('https server '.blue + 'started '.green.bold + 'on port '.blue + '3000 '.yellow);

证书也是从库中获取的,我也尝试使用有效的证书,它们可以在直接的 https 服务器上运行,但不能用作代理。

作为代理 - 我得到 Secure Connection Failed

TL;DR 问题

有谁知道如何使用 nodejs 实现 HTTPS 代理服务器?

类似的未解决帖子:

Https proxy server(secure proxy server) in Nodejs with http-proxy is not working

https://github.com/http-party/node-http-proxy/issues/1456

https://github.com/http-party/node-http-proxy/issues/1506

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)