简体   繁体   English

运行Fiddler作为HTTPS服务器的反向代理

[英]Running Fiddler as a Reverse Proxy for HTTPS server

I have the following situation: 2 hosts, one is a client and the other an HTTPS server. 我有以下情况:2台主机,一台是客户端,另一台是HTTPS服务器。

Client (:<brwsr-port>) <=============> Web server (:443)

I installed Fiddler on the server so that I now have Fiddler running on my server on port 8888. 我在服务器上安装了Fiddler ,这样我就可以在我的服务器端口8888上运行Fiddler了。

The situation i would like to reach is the following: 我想达到的情况如下:

|Client (:<brwsr-port>)| <===> |Fiddler (:8888) <===> Web server (:443)|
|-Me-------------------|       |-Server--------------------------------|

From my computer I want to contact Fiddler which will redirect traffic to the web server. 从我的电脑我想联系Fiddler,它将流量重定向到Web服务器。 The web server however uses HTTPS. 然而,Web服务器使用HTTPS。

On The server I set up Fiddler to handle HTTPS sessions and decrypt them. 在服务器上,我设置了Fiddler来处理HTTPS会话并解密它们。 I was asked to install on the server Fiddler's fake CA's certificate and I did it! 我被要求在服务器上安装Fiddler的假CA证书,我做到了! I also inserted the script suggested by the Fiddler wiki page to redirect HTTPS traffic 我还插入了Fiddler维基页面建议的脚本来重定向HTTPS流量

// HTTPS redirect ----------------------- 
FiddlerObject.log("Connect received...");
if (oSession.HTTPMethodIs("CONNECT") && (oSession.PathAndQuery == "<server-addr>:8888")) {
    oSession.PathAndQuery = "<server-addr>:443";
}
// --------------------------------------

However when I try https://myserver:8888/index.html I fail! 但是,当我尝试https://myserver:8888/index.html我失败了!

Failure details 失败的细节

When using Fiddler on the client, I can see that the CONNECT request starts but the session fails because response is HTTP error 502. Looks like no one is listening on port 8888. In fact, If I stop Fiddler on the server I get the same situation: 502 bad gateway. 在客户端上使用Fiddler时,我可以看到CONNECT请求启动但会话失败,因为响应是HTTP错误502.看起来没有人在端口8888上侦听。事实上,如果我在服务器上停止Fiddler,我会得到相同的情况:502坏网关。

Please note that when I try https://myserver/index.html and https://myserver:443/index.html everything works! 请注意,当我尝试https://myserver/index.htmlhttps://myserver:443/index.html一切正常!

Question

What am I doing wrong? 我究竟做错了什么?

Is it possible that...? 有可能......?

I thought that since maybe TLS/SSL works on port 443, I should have Fiddler listen there and move my web server to another port, like 444 (I should probably set on IIS an https binding on port 444 then). 我认为,因为TLS / SSL可能在端口443上运行,我应该让Fiddler在那里监听并将我的Web服务器移动到另一个端口,例如444(我应该在IIS上设置一个https绑定在444端口)。 Is it correct? 这是正确的吗?

If Fiddler isn't configured as the client's proxy and is instead running as a reverse proxy on the Server, then things get a bit more complicated. 如果未将Fiddler配置为客户端的代理,而是在服务器上作为反向代理运行,则事情会变得复杂一些。

Running Fiddler as a Reverse Proxy for HTTPS 运行Fiddler作为HTTPS的反向代理

  1. Move your existing HTTPS server to a new port (eg 444) 将现有HTTPS服务器移动到新端口(例如444)
  2. Inside Tools > Fiddler Options > Connections, tick Allow Remote Clients to Connect . 在工具>提琴选项>连接内,勾选Allow Remote Clients to Connect Restart Fiddler. 重启Fiddler。
  3. Inside Fiddler's QuickExec box, type !listen 443 ServerName where ServerName is whatever the server's hostname is; 在Fiddler的QuickExec框中,输入!listen 443 ServerName其中ServerName是服务器的主机名; for instance, for https://Fuzzle/ you would use fuzzle for the server name. 例如,对于https://Fuzzle/您将使用fuzzle作为服务器名称。
  4. Inside your OnBeforeRequest method, add: 在OnBeforeRequest方法中,添加:

     if ((oSession.HostnameIs("fuzzle")) && (oSession.oRequest.pipeClient.LocalPort == 443) ) { oSession.host = "fuzzle:444"; } 

Why do you need to do it this way? 你为什么需要这样做?

The !listen command instructs Fiddler to create a new endpoint that will perform a HTTPS handshake with the client upon connection; !listen命令指示Fiddler创建一个新端点,该端点将在连接时与客户端执行HTTPS握手; the default proxy endpoint doesn't do that because when a proxy receives a connection for HTTPS traffic it gets a HTTP CONNECT request instead of a handshake. 默认代理端点不这样做,因为当代理收到HTTPS流量的连接时,它会获得HTTP CONNECT请求而不是握手。

I just ran into a similar situation where I have VS2013 (IISExpress) running a web application on HTTPS (port 44300) and I wanted to browse the application from a mobile device. 我刚遇到类似的情况,我有VS2013(IISExpress)在HTTPS(端口44300)上运行Web应用程序,我想从移动设备浏览应用程序。

I configured Fiddler to "act as a reverse proxy" and "allow remote clients to connect" but it would only work on port 80 (HTTP). 我将Fiddler配置为“充当反向代理”并“允许远程客户端连接”但它只能在端口80(HTTP)上工作。

Following on from EricLaw's suggestion, I changed the listening port from 8888 to 8889 and ran the command " !listen 8889 [host_machine_name] " and bingo I was able to browse my application on HTTPS on port 8889. 根据EricLaw的建议,我将监听端口从8888更改为8889并运行命令“ !listen 8889 [host_machine_name] ”和bingo我能够在端口8889上通过HTTPS浏览我的应用程序。

Note: I had previously entered the forwarding port number into the registry ( as described here ) so Fiddler already knew what port to forward the requests on to. 注意:我之前已将转发端口号输入注册表( 如此处所述 ),因此Fiddler已经知道要将请求转发到哪个端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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