Mac 内网穿透
内网穿透,通常用于向外网用户展示本机的一些Demo或项目,或者用于一些第三方的调试,比如支付宝和微信的一些开放功能。
内网穿透工具,在Windows下可以使用花生壳,很方便。但是花生壳并没有Mac版本,在Mac下,则可以使用ngrok
,比花生壳更方便。
官方下载
官方下载地址
下载后解压到自定义目录即可
简单配置
cd进入该目录,执行命令,启动ngrok
./ngrok http localhost:8080
控制台开始进行域名分配,过程中链接状态会不停切换,展示如下页面,代表分配外网域名成功(Status为online)
Session Status online
Session Expires 7 hours, 57 minutes
Version 2.2.8
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://2d9a8919.ngrok.io -> localhost:8080
Forwarding https://2d9a8919.ngrok.io -> localhost:8080
外网链接每次启动都会变
此时访问外网地址http://2d9a8919.ngrok.io
就相当于访问本地的localhost:8080
,而且从控制台输出也可以看出,已经同时提供了http和https,非常方便。
一切的一切,只有一行命令。
注意事项
外网链接每次ngrok
服务重新启动都会变。
查看使用帮助
如果想查看更多信息,既可以查看官方文档,也可以在控制台执行命令,查看简介及常用配置
./ngrok help
控制台输出内容
COMMANDS:(常用命令:)
authtoken save authtoken to configuration file
credits prints author and licensing information
http start an HTTP tunnel
start start tunnels by name from the configuration file
tcp start a TCP tunnel
tls start a TLS tunnel
update update ngrok to the latest version
version print the version string
help Shows a list of commands or help for one command
EXAMPLES:(使用示例:)
ngrok http 80 # secure public URL for port 80 web server
ngrok http -subdomain=baz 8080 # port 8080 available at baz.ngrok.io
ngrok http foo.dev:80 # tunnel to host:port instead of localhost
ngrok tcp 22 # tunnel arbitrary TCP traffic to port 22
ngrok tls -hostname=foo.com 443 # TLS traffic for foo.com to port 443
ngrok start foo bar baz # start tunnels from the configuration file