微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Nodejs HTTPS->HTTPS 代理

如何解决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 举报,一经查实,本站将立刻删除。