whistle不錯的代理軟體
whistle 功能簡介
- 檢視 HTTP、HTTPS、HTTP2、WebSocket、TCP 請求響應資料
- 修改 HTTP、HTTPS、HTTP2、WebSocket、TCP 請求響應資料
- 修改請求 url、方法、頭部、內容等
- 修改響應狀態碼、頭部、內容,並支援本地替換等
- 修改 WebSocket 和 TCP 收發的幀資料
- 設定 hosts(支援 IPv6)、http-proxy、https-proxy、socks
- 作為HTTP代理或反向代理
- 整合常用的 web 除錯工具,如 weinre 和 log 等
- 支援用 Node 編寫外掛擴充套件
安裝啟動
whistle安裝過程需要以下步驟(缺一不可):
- 安裝Node
- 安裝whistle
- 啟動whistle
- 配置代理
- 安裝根證書
1. 安裝Node
whistle支援v0.10.0
以上版本的Node,為獲取更好的效能,推薦安裝最新版本的Node。
如果你的系統已經安裝了v0.10.0
以上版本的Node,可以忽略此步驟,直接進入安裝whistle的步驟,否則:
- Windows或Mac系統,訪問https://nodejs.org/,安裝LTS版本的Node,預設安裝即可。
- Linux下推薦使用原始碼安裝: 從Node官網下載最新版的Source Code(或者用
wget
命令下載),解壓檔案(tar -xzvf node-vx.y.z.tar.gz
)後進入解壓後的根目錄(node-vx.y.z
./configure
、./make
和./make install
。
安裝完Node後,執行下面命令,檢視當前Node版本
$ node -v v4.4.0
如果能正常輸出Node的版本號,表示Node已安裝成功(Windows系統可能需要重新開啟cmd)。
2. 安裝whistle
Node安裝成功後,執行如下npm命令安裝whistle (Mac或Linux的非root使用者需要在命令列前面加sudo
,如:sudo npm install -g whistle
)
$ npm install -g whistle
npm預設映象是在國外,有時候安裝速度很慢或者出現安裝不了的情況,如果無法安裝或者安裝很慢,可以使用taobao的映象安裝:
$ npm install cnpm -g --registry=https://registry.npm.taobao.org $ cnpm install -g whistle
或者直接指定映象安裝:
$ npm install whistle -g --registry=https://registry.npm.taobao.org
whistle安裝完成後,執行命令whistle help
或w2 help
,檢視whistle的幫助資訊
$ w2 help Usage: whistle <command> [options] Commands: status Show the running status of whistle use/add [filepath] Set rules from a specified js file (.whistle.js by default) 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: -h, --help output usage information -D, --baseDir [baseDir] set the configured storage root path -z, --certDir [directory] set custom certificate store directory -l, --localUIHost [hostname] set the domain for the web ui of whistle (local.whistlejs.com by default) -L, --pluginHost [hostname] set the domain for the web ui of plugin (as: "script=a.b.com&vase=x.y.com") -n, --username [username] set the username to access the web ui of whistle -w, --password [password] set the password to access the web ui of whistle -N, --guestName [username] set the the guest name to access the web ui of whistle (can only view the data) -W, --guestPassword [password] set the guest password to access the web ui of whistle (can only view the data) -s, --sockets [number] set the max number of cached long connection on each domain (60 by default) -S, --storage [newStorageDir] set the configured storage directory -C, --copy [storageDir] copy the configuration of the specified directory to a new directory -c, --dnsCache [time] set the cache time of DNS (30000ms by default) -H, --host [boundHost] set the bound host of whistle (INADDR_ANY by default) -p, --port [proxyPort] set the proxy port of whistle (8899 by default) -P, --uiport [uiport] set the listening port of whistle webui -m, --middlewares [script path or module name] set the express middlewares loaded at startup (as: xx,yy/zz.js) -M, --mode [mode] set the way of starting the whistle mode (as: pureProxy|debug|multiEnv) -t, --timeout [ms] set the request timeout (66000ms by default) -e, --extra [extraData] set the extra parameters for plugin -f, --secureFilter [secureFilter] set the path of secure filter -R, --reqCacheSize [reqCacheSize] set the cache size of request data (600 by default) -F, --frameCacheSize [frameCacheSize] set the cache size of webSocket and socket's frames (512 by default) -A, --addon [pluginPaths] add custom plugin paths --httpPort [httpPort] set the http server port of whistle --httpsPort [httpsPort] set the https server port of whistle --no-global-plugins do not load any globally installed plugins --no-prev-options do not reuse the previous options when restarting -V, --version output the version number
如果能正常輸出whistle的幫助資訊,表示whistle已安裝成功。
3. 啟動whistle
最新版本的whistle支援三種等價的命令
whistle
、w2
、wproxy
啟動whistle:
$ w2 start
Note: 如果要防止其他人訪問配置頁面,可以在啟動時加上登入使用者名稱和密碼-n yourusername -w yourpassword
。
重啟whsitle:
$ w2 restart
停止whistle:
$ w2 stop
除錯模式啟動whistle(主要用於檢視whistle的異常及外掛開發):
$ w2 run
啟動完whistle後,最後一步需要配置代理。
4. 配置代理
配置資訊
- 代理伺服器:127.0.0.1 (如果部署在遠端伺服器或虛擬機器上,改成對應伺服器或虛擬機器的ip即可)
- 預設埠:8899 (如果埠被佔用,可以在啟動時通過
-p
來指定新的埠,更多資訊可以通過執行命令列w2 help
(v0.7.0
及以上版本也可以使用w2 help
) 檢視)
勾選上對所有協議均使用相同的代理伺服器
代理配置方式(把上面配置資訊配置上即可)
具體代理設定方式請自行搜尋
訪問配置頁面
啟動whistle及配置完代理後,用Chrome瀏覽器(由於css相容性問題介面只支援Chrome瀏覽器)訪問配置頁面,如果能正常開啟頁面,whistle安裝啟動完畢,可以開始使用。
可以通過以下兩種方式來訪問配置頁面:
- 方式1:域名訪問http://local.whistlejs.com/
- 方式2:通過ip+埠來訪問,形式如
http://whistleServerIP:whistlePort/
e.g.http://127.0.0.1:8899 - 方式2:通過命令列引數
-P xxxx
自定義webui的埠(xxxx
表示要設定的埠號),自定義埠支援上述兩種方式訪問,也支援http://127.0.0.1:xxxx