为什么要用内网穿透
- 我们想要让其他的人访问到我写的项目的时候,可以用穿透我们项目的 IP 让他进行访问
- 我们在开发的时候,微信支付的回调,或者支付宝的回调,等等…
工具
- 钉钉提供的内网穿透工具(pierced:https://github.com/open-dingtalk/pierced)
- Ngrok (https://ngrok.com)
使用
pierced
1.下载
git clone https://github.com/open-dingtalk/pierced.git
2.说明可以去看一下官网:https://github.com/open-dingtalk/pierced
3.他有三个操作系统分别是:Win,Mac,Linux,找到你要用的文件夹中,在使用命令行
4.进入文件夹中使用命令行,cmd也行
5.运行使用,首先你的那个项目启动的
注意:
- newmonster 这是域名
- 8080 这是你的项目端口号
- 方式一
.\ding -config=.\ding.cfg -subdomain=newmonster 8080
- 方式二
ding.exe -config=./ding.cfg -subdomain=newmonster 8080
之所以写两种是怕不同,如果第一种就行,就不用第二种启动了
启动成功后,会在控制台打印出2个URL
http://newmonster.vaiwan.com
https://newmonster.vaiwan.com
然后哪这去浏览器访问即可
Ngrok
1.下载
https://ngrok.com/download
2.下载完之后,解压出来只有一个exe文件
3.使用
首先我们需要去 ngrok 官网获取授权码 (https://dashboard.ngrok.com/login),先登录之后
- 找到setup & installation
- 双击打开你的 ngrok.exe的软件
- 在setup & installation里面有授权码,运行一次就行了 ( ngrok authtoken xxxxxx )
- 使用就是 ngrok http 8080
说明:
- Ngrok http 8080 这个8080是你的项目端口
- 成功后会出现 forwarding 的地址 那两个 http 和 https 的地址是你给别人访问的