一文教你配置whistle代理

2,507 阅读2分钟

whistle:基于Node实现的跨平台web调试代理工具,类似的工具有Windows平台上的Fiddler,主要用于查看、修改HTTP、HTTPS、Websocket的请求、响应,也可以作为HTTP代理服务器使用,不同于Fiddler通过断点修改请求响应的方式,whistle采用的是类似配置系统hosts的方式,一切操作都可以通过配置实现,支持域名、路径、正则表达式、通配符、通配路径等多种匹配方式

1. 安装Node

whistle支持v0.10.0以上版本的Node。

访问NodeJs官网下载,推荐安装LTS版本的Node。

$ node -v 可查看node版本。

2. 安装whistle

$ npm install -g whistle

whistle安装完成后,可执行命令 whistle helpw2 help查看whistle的帮助信息。

若能正确输出帮助信息,则安装成功。

  Usage: whistle <command> [options]
​
  Commands:
​
    status          Show the running status
    add [filepath]  Add rules from local js file (.whistle.js by default)
    install         Install a whistle plugin
    uninstall       Uninstall a whistle plugin
    exec            Exec whistle plugin command
    run             Start a front service
    start           Start a background service
    stop            Stop current background service
    restart         Restart current background service
    help            Display help information
​
  Options:
  ……
​

3. 启动whistle

最新版本的whistle支持三种等价的命令whistlew2wproxy

  • 启动whistle

    $ w2 start

    $ w2 start -P xxxx (指定启动端口为xxxx)

    whistle启动:

    [!] whistle@2.5.28 is running
    [i] 1. use your device to visit the following URL list, gets the IP of the URL you can access:
           http://127.0.0.1:8899/
           http://10.65.93.79:8899/
           http://192.168.255.10:8899/
           Note: If all the above URLs are unable to access, check the firewall settings
                 For help see https://github.com/avwo/whistle
    [i] 2. configure your device to use whistle as its HTTP and HTTPS proxy on IP:53734
    [i] 3. use Chrome to visit http://local.whistlejs.com/ to get started
    
  • 访问配置界面

    启动whistle后,可使用Chrome浏览器访问配置界面,访问方式可选择:

    1. ip + 端口访问:http://127.0.0.1:8899/
    2. 域名访问:local.whistlejs.com/
  • 停止whistle

    $ w2 stop

  • 重启whistle

    $ w2 restart

4. 配置host

在配置界面进入“Rules”选项,输入配置的host,点击“Save”进行保存,双击规则进行启用或关闭。

image-20201202174744885.png

5. 配置代理

  • 配置所有浏览器代理

    推荐使用浏览器插件:SwitchyOmega

    image-20201202150248143.png

    1. 新建一个情景模式,选择代理服务器类型。
    2. 配置代理服务器,代理端口与启动的代理服务器端口一致。
    3. 记得删除“不代理的地址列表”中默认的内容。
    4. 点击应用选项来保存应用。
    5. 选择刚刚配置的模式。

    image-20201202150924698.png

  • 配置全局代理

    系统偏好设置 > 网络 > 高级 > 代理

    设置网页代理(HTTP),配置网页代理服务器。

    image-20201202152040317.png

6. 安装根证书

  • 下载根证书

    image-20201202152522830.png

  • 手动信任证书

    在证书管理器中找到最新下载的证书

    image-20201202152916270.png

    双击证书,改为“始终信任”,按提示输入管理员密码,完成。

    image-20201202153317527.png

完成!