ngrok 实现内网穿透,获取临时域名

开发调试中会遇到这样的问题,服务运行在本地机器上,想让外网访问本地机器的服务,就要提供公网地址。但大多数情况下,本地机器在内网,还需要穿透NAT网络和防火墙。ngork 正好解决了这个痛点,可以提供临时的URL,让外网访问到本地机器上的web服务。

原理:

本地起一个服务ngrok-local,和官方服务ngrok-server建立了一个tcp连接,ngrok-server将随机二级域名 http://xxxxxxxxxxx.ngrok.io 下的流量转发到ngrok-local,ngrok-local 再将流量代理到本地服务。

在这里插入图片描述

ngrok 使用例子

  • 官网 下载ngrok的二进制静态文件

  • 配置账号,只需要配置一个token,该 token 在官网首页可以找到

./ngrok authtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  • 启动http隧道,代理到本地端口80080

./ngrok http 8080

ngrok by @inconshreveable                                                                                                                                                                                                     (Ctrl+C to quit)

Session Status                online
Account                       John (Plan: Free)
Version                       2.3.40
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://xxxxxxxxxxx.ngrok.io -> http://localhost:8080
Forwarding                    https://xxxxxxxx.ngrok.io -> http://localhost:8080

Connections                   ttl     opn     rt1     rt5     p50     p90
                              3       0       0.00    0.00    0.00    0.00

HTTP Requests
-------------

GET /doc/                      200 OK
GET /favicon.ico               404 File not found
GET /                          200 OK

外网访问 http://xxxxxxxxxxx.ngrok.io 的请求,会被转发到本地地址 http://localhost:8080。 http://localhost:4040 地址可以查看具体的请求。

帮助文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值