用户指南
Ngrok 内网透传插件

Ngrok 内网透传插件

Ngrok 是一个开源的网络代理工具,它允许你将本地开发环境的端口映射到互联网上,从而使远程用户能够通过浏览器访问你的本地服务。这对于测试、演示或远程调试应用程序非常有用,特别是在需要从外部访问本地网络服务时。Ngrok 的主要特点包括:

  1. 端口映射:它允许你将本地机器上的任意端口映射到互联网上,通常是通过一个自定义的 URL。
  2. HTTP/HTTPS 隧道:Ngrok 支持 HTTP 和 HTTPS 隧道,这意味着你可以通过安全的加密连接访问你的本地服务。
  3. 远程访问:它允许你从任何地方访问你的本地服务,无论是通过电脑、手机还是平板电脑。
  4. 安全认证:Ngrok 提供了一个安全认证系统,允许你限制对映射服务的访问。

Ngrok 插件

本插件借助 Ngrok 提供的免费服务,实现将本地端口映射到公网,从而实现内网透传。

申请 Token

登录 https://dashboard.ngrok.com (opens in a new tab)。注册一个账号,然后进入首页:

plugin

选择你的 Token:

plugin

或者可以创建一个域名:

plugin

将上面申请到的 Token 配置到 RHILEX 的配置文件中,下个段落将详细介绍。

配置参数

rhilex.ini
[plugin.ngrokc]
# Website: https://www.ngrok.com
 
# Enable the plugin
enable = true
# Server endpoint address
server_endpoint = "default"
# Ngrok domain
domain = "workable-logically-tarpon.ngrok-free.app"
# Authentication token
auth_token = "2oNcHbuj*****qkTGutMjq6E"
# tcp | http | https
local_schema = "http"
# Local IP address
local_host = "127.0.0.1"
# Local port
local_port = 2580
 

关键配置:

  • enable:开启、关闭插件
  • auth_token:Ngrok 申请到的 token,例如 "2oNcHbuj*****qkTGutMjq6E"
  • domain:Ngrok 申请到的域名,例如 workable-logically-tarpon.ngrok-free.app
  • local_schema :要映射到公网的协议
  • local_host:要映射到公网的主机 IP
  • local_port:要映射到公网的端口

配置好以后启动 RHILEX,可以在“增强插件”功能菜单处找到 Ngrok 插件。

plugin

点击“详情”可以看到状态:

plugin

如果你的网络能正确连接到互联网,你可以通过 workable-logically-tarpon.ngrok-free.app 来访问位于内网的 RHILEX。

plugin

连接失败日志:

JSON
{
    "appId": "rhilex",
    "file": "C:/Users/wangwenhai/workspace/rhilex/plugin/ngrokc/ngrok_client.go:170",
    "func": "github.com/hootrhino/rhilex/plugin/ngrokc.(*NgrokClient).startClient.func2.3",
    "level": "error",
    "msg": "failed to send authentication request: read tcp 192.168.10.3:51901->18.177.129.29:443: wsarecv: An existing connection was forcibly closed by the remote host.",
    "time": "2024-11-04T17:53:33.9356241+08:00"
}
💡

Ngrok 在国内网络会受阻,导致一直连接失败的情况,请保证你的网络能正确连接到互联网。

© 2023-2025 RHILEX Technologies Inc. All rights reserved.