I would like to create a proxy for HTTPS connections with Node.js. I am using the http-proxy library, which works well. I can get a HTTP proxy to work perfectly, but when I try HTTPS, the request to the proxy just times out. Here is my code (a slightly modified version of the node-http-proxy proxy-https-to-https example):
var http = require("http"),
    https = require("https"),
    httpProxy = require("http-proxy"),
    fs = require('fs');
var httpsConfig = {
  key: fs.readFileSync('./jackos2500-key.pem'),
  cert: fs.readFileSync('./jackos2500-cert.crt'),
};
https.createServer(httpsConfig, function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('hello https\n');
    res.end();
}).listen(8000);
httpProxy.createServer(8000, 'localhost', {
  https: httpsConfig,
  target: {
    https: true,
    rejectUnauthorized: false
  }
}).listen(443);
Is there something obvious I'm missing here or is there some other issue?
I am getting the same issue. I see nothing logged. Here is mine, which is a little different (the second one matches the examples I see from the github examples):
var https = require('https');
var httpProxy = require('http-proxy/lib/node-http-proxy');
var helpers = require('http-proxy/test/helpers');
var request = require('request');
https.createServer(function(req, response) {
  try {
    console.log("forwarding https", req);
    var proxy_request = request(req);
    proxy_request.pipe(response);
  } catch (err) {
    console.log("Forwarding server caught error:\n" + err + "\n")
  }
}).listen(9001);
httpProxy.createServer(function (req, res, proxy) {
  console.log("Got request!");
  proxy.proxyRequest(req, res, {
    port: 9001,
    host: 'localhost',
    buffer: httpProxy.buffer(req)
  });
}, { https: helpers.https }).listen(8001);
...I have also tried the simpler one:
httpProxy.createServer(9001,
  'localhost',
  { https: helpers.https }).listen(8001)
When I set Firefox's https proxy port to 8001 and go anywhere, I get "The connection was reset".
I do exactly the same thing with 'http' replacing 'https', and it all works just fine.
There is an open issue for node-http-proxy
https://github.com/nodejitsu/node-http-proxy/issues/454#issuecomment-25661401