具有http-proxy的Node.js中的HTTPs代理服务器(安全代理服务器)不起作用

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

我需要设置一个https代理服务器(安全Web代理-http://dev.chromium.org/developers/design-documents/secure-web-proxy),以使用代理环境测试我的应用程序之一。

已执行的步骤:1.借助http-proxy创建一个https代理服务器。代码,

    var https = require('https'),
    http = require('http'),
    util = require('util'),
    fs   = require('fs'),
    path = require('path'),
    colors = require('colors'),
    httpProxy = require('http-proxy'),
   // fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures'),   
    httpsOpts = {
      key: fs.readFileSync('server.key', 'utf8'),
      cert: fs.readFileSync('server.crt', 'utf8')
    };

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

//
// Create the proxy server listening on port 8010
//
httpProxy.createServer({
  ssl: httpsOpts,
  target: 'https://localhost:9010',
  secure: false
}).listen(8010);

console.log('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8010'.yellow);
console.log('https server '.blue + 'started '.green.bold + 'on port '.blue + '9010 '.yellow);
  1. 使用https代理服务器详细信息创建了PAC文件
function FindProxyForURL(url, host) {    
  return "HTTPS 127.0.0.1:8010";
}
  1. 然后将pac文件指向我的应用程序,以使用代理环境测试应用程序,并将示例代码粘贴到此处。
var url = require('url');
var https = require('https');
var PacProxyAgent = require('pac-proxy-agent');

// URI to a PAC proxy file to use (the "pac+" prefix is stripped)
var proxy = 'pac+http://localhost:123/hosted/pac.pac';
//console.log('using PAC proxy proxy file at %j', proxy);

// HTTP endpoint for the proxy to connect to
var endpoint = 'https://nodejs.org/api/';
//console.log('attempting to GET %j', endpoint);
var opts = url.parse(endpoint);

// create an instance of the `PacProxyAgent` class with the PAC file location
var agent = new PacProxyAgent(proxy,opts);
opts.agent = agent;

https.get(opts, function (res) {
  console.log('"response" event!', res.headers);
  res.pipe(process.stdout);
});

但是它不起作用,它会引发错误

enter image description here

Chrome行为:

我在Windows代理设置中配置了PAC文件enter image description here

此后,我没有收到任何网站的任何回复例如:当我输入https://gmail.com/时,其结尾为

enter image description here

有什么建议吗?

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

这将不起作用,因为您正在自行创建SSL证书。您可以在浏览器上使用它,但是它将显示它未被浏览器验证。因此,您必须使用将由主机提供商提供的经过验证的证书。

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