简体   繁体   中英

HTTPS proxy with a self-signed certificate in Node.JS

I'm trying to create a HTTPS proxy server in Node.JS v0.10.24 using a self-signed certificate. Here's the code I'm using:

var https = require('https');

var server = https.createServer({
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
});

server.on('request', function(req, res) {
  res.end('hello');
});

server.listen(8080);

This server correctly boots up and is accessible via https://localhost:8080 . However, when I set it as a HTTPS proxy (on Mac OS X), the server emits connection events but never emits either request or error , thus causing the connection to hang indefinitely and eventually time out.

I encountered the same issue on my Macbook. The issue appears to be that the proxy server option in OSX is using the HTTP CONNECT method to tunnel HTTPS requests.

In short, this means that you need make your server a http.Server instance and handle the connect event, which will involve forwarding TCP socket traffic.

I know this reply is a bit late, but I wrote my own HTTP/S proxy server that you can look at for reference: https://github.com/robu3/purokishi . The specific section covering the connect method is here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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