在Node.JS中使用自签名证书的HTTPS代理

时间:2022-12-25 16:57:13

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:

我正在尝试使用自签名证书在Node.JS v0.10.24中创建HTTPS代理服务器。这是我正在使用的代码:

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.

此服务器正确启动,可通过https:// localhost:8080访问。但是,当我将其设置为HTTPS代理(在Mac OS X上)时,服务器会发出连接事件但从不发出请求或错误,从而导致连接无限期挂起并最终超时。

1 个解决方案

#1


1  

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.

我在Macbook上遇到了同样的问题。问题似乎是OSX中的代理服务器选项正在使用HTTP CONNECT方法来隧道传输HTTPS请求。

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.

简而言之,这意味着您需要使服务器成为http.Server实例并处理connect事件,这将涉及转发TCP套接字流量。

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.

我知道这个回复有点晚了,但我编写了自己的HTTP / S代理服务器,您可以查看以供参考:https://github.com/robu3/purokishi。这里介绍了连接方法的具体部分。

#1


1  

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.

我在Macbook上遇到了同样的问题。问题似乎是OSX中的代理服务器选项正在使用HTTP CONNECT方法来隧道传输HTTPS请求。

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.

简而言之,这意味着您需要使服务器成为http.Server实例并处理connect事件,这将涉及转发TCP套接字流量。

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.

我知道这个回复有点晚了,但我编写了自己的HTTP / S代理服务器,您可以查看以供参考:https://github.com/robu3/purokishi。这里介绍了连接方法的具体部分。