Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Http-proxy HTTPS Balancer error #489

Open
luiscappabanda opened this Issue Sep 24, 2013 · 0 comments

Comments

Projects
None yet
1 participant

I´ve been trying for two days to develop a proxy balancer that:

  1. Receives a requesting HTTP/S URL.
  2. Selects a Proxy from a list.
  3. Dispatches the requested HTTP/S URL to that target proxy.

My first attemp with HTTP URL Request was fantastic, and everything was OK, but doing the same with HTTPs URLS doesn´t work. The code is simple, and I´ve read http-proxy documentation plus some question answers here, but still doesn´t work.

Here is the code:

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

var fs = require('fs');

var addresses = [
{
host: 'localhost',
port: 3128
},
{
host: 'otherIP',
port: 3128
}
];

var httpsOptions = {
https: {
key: fs.readFileSync('./ssl/key.pem', 'utf8').toString(),
cert: fs.readFileSync('./ssl/key-cert.pem', 'utf8').toString()
}
};

var proxy = new httpProxy.RoutingProxy({
target: {
https: true
}
});

var counter = 0;

https.createServer(httpsOptions.https, function (req, res) {
console.log("URL="+req.url);
var target = addresses.shift();
addresses.push(target);
proxy.proxyRequest(req, res, target);

proxy.on('end', function() {
console.log('Proxied ('+counter+'). URL='+req.url);
});

proxy.on('proxyError', function (err, req, res, counter) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Something went wrong. And we are reporting a custom error message.');

});

}).listen(443);

The code is pretty simple: it creates a HTTPS server listening to 443 port using a self-signed certificate. There is also a RoutingProxy that dispatches the HTTPs URL to the proxy selected from the list. Optional parameters such as https=true are setted.

However, when launching the Node.Js code and configuring Firefox pointing to localhost 443 proxy and then loading, for example, https://www.google.com or https://www.facebook.com doesn´t work: page waits loading and loading and never load and the request never 'enters' into https Server and prints the console.log message.

Can anyone help me, please?

Thank you very much in advance,

Best regards,

Luis Cappa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment