原帖收藏於IT老兵博客。html
微信開發:NAT穿透。web
調試微信,遇到問題,微信沒法直接通知到開發機上,而是須要一臺服務器的地址上,這給調試增長了難度,上網研究了一下,若是在windows下,能夠使用花生殼軟件,進行NAT穿透,可是花生殼不支持mac,又找了找,發現了ngrok,這個配置很簡單,解決了問題。windows
一共須要四步:瀏覽器
Download ngrok
First, download the ngrok client, a single binary with zero run-time dependencies.
Mac OS XWindows Linux Mac (32-bit) Windows (32-bit)Linux (ARM) Linux (ARM64) Linux (32-bit)FreeBSD (64-Bit) FreeBSD (32-bit)tomcat
第一步,下載ngrok,它支持Mac、Linux、Windows等多個操做系統。服務器
Unzip to install
On Linux or OSX you can unzip ngrok from a terminal with the following command. On Windows, just double click ngrok.zip.
unzip /path/to/ngrok.zip
Most people like to keep ngrok in their primary user folder or set an alias for easy command-line access.微信
第二步,解壓縮。微信開發
Connect your account
Running this command will add your authtoken to your ngrok.yml file. Connecting an account will list your open tunnels in the dashboard, give you longer tunnel timeouts, and more. Visit the dashboard to get your auth token.ide
./ngrok authtoken <YOUR_AUTH_TOKEN>
Don’t have an account?
Sign up for free to get your auth token.svg
第三步,註冊帳號,點擊上面的Sign up連接,去註冊,或者使用谷歌帳戶受權,有了受權,這個工具會提供更好的支持。
Fire it up
Try it out by running it from the command line:
./ngrok help
To start a HTTP tunnel on port 80, run this next:
./ngrok http 80
Read the documentation to get more ideas on how to use ngrok.
第四部,開始使用,./ngrok help
能夠獲取幫助,./ngrok http 80
開始運行,注意80是你想要反向代理的端口,這個要根據你的需求來設置,例如這裏是tomcat,端口是8080,那麼上面要改爲8080。
運行起來以後,它會給你分配一個動態的域名,如上圖,在瀏覽器訪問這個域名,就能夠訪問到你的服務了。
工欲善其事,必先利其器。微信開發,若是不配置好這個回調,那麼每次都須要部署到服務器上才能驗證,這樣效率會低不少。