使用节点的代理HTTP到HTTPS

问题描述 投票:0回答:1

如何使用NodeJS将第三方网站从HTTP代理到HTTPS?

例如,我希望我的用户以http://somesite.com身份访问https://localhost:8001

我尝试使用http-proxy库,遵循其在HTTP-> HTTPS部分中的示例,但是我得到的只是空响应错误。

node.js http proxy http-proxy
1个回答
0
投票

http-proxy模块应该工作。请尝试下面的示例https://google.com

var https = require('https'),
httpProxy = require('http-proxy');

//
// Create a HTTP Proxy server with a HTTPS target
//
httpProxy.createProxyServer({
  target: 'https://google.com',
  agent  : https.globalAgent,
  secure : false,
  headers: {
    host: 'google.com'
  }
}).listen(8011);

示例git repo是here

© www.soinside.com 2019 - 2024. All rights reserved.