我需要设置一个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);
function FindProxyForURL(url, host) { return "HTTPS 127.0.0.1:8010"; }
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); });
但是它不起作用,它会引发错误
Chrome行为:
此后,我没有收到任何网站的任何回复例如:当我输入https://gmail.com/时,其结尾为
有什么建议吗?
这将不起作用,因为您正在自行创建SSL证书。您可以在浏览器上使用它,但是它将显示它未被浏览器验证。因此,您必须使用将由主机提供商提供的经过验证的证书。