微信开发:NAT穿透

原帖收藏于IT老兵博客

微信开发:NAT穿透。

前言

调试微信,遇到问题,微信无法直接通知到开发机上,而是需要一台服务器的地址上,这给调试增加了难度,上网研究了一下,如果在windows下,可以使用花生壳软件,进行NAT穿透,但是花生壳不支持mac,又找了找,发现了ngrok,这个配置很简单,解决了问题。

正文

一共需要四步:

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)

第一步,下载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.

1
./ngrok authtoken <YOUR_AUTH_TOKEN>

Don’t have an account?
Sign up for free to get your auth token.

第三步,注册账号,点击上面的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。

在这里插入图片描述

运行起来之后,它会给你分配一个动态的域名,如上图,在浏览器访问这个域名,就可以访问到你的服务了。

总结

工欲善其事,必先利其器。微信开发,如果不配置好这个回调,那么每次都需要部署到服务器上才能验证,这样效率会低很多。