繁体   English   中英

使用节点代理 HTTP 到 HTTPS

[英]Proxy HTTP to HTTPS using Node

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

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

我已经尝试使用 http-proxy 库,按照他们在 HTTP -> HTTPS 部分中的示例,但我得到的只是空响应错误。

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 示例在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM