JAY站

Valar Morghulis Valar Dohaeris

静下心来,用心观察 处处都透着生活的美.


ngrok

概念用途

ngrok是非常流行的反向代理服务,可以进行内网穿透,支持80端口以及自定义tcp端口转发. 这样你就可以运行本地的程序,而让别人通过公网访问了.

安装

1、官网下载地址下载, 解压

2、将可执行文件ngrok移到系统的bin文件夹内(或者将快捷链接移动到bin目录下),注意是系统目录,不是用户目录.

3、只有这样,才可以在命令行执行ngrok,而不会得到command not found的错误信息.

使用说明

1、 If you don’t know what port your web server is listening on, it’s probably port 80, the default for HTTP. »»>终端执行下面的命令 , 也就是监测web server的运行端口,默认是80 .

ngrok http 8080

这里因为我需要访问的是本地运行的jenkins,而它运行的端口是8080,当然你也可以改,不过一般默认即可,除非有端口冲突.

2、 如果没有报错,说明运行正常,这个时候,终端会出现下面的信息

ngrok by @inconshreveable                                       (Ctrl+C to quit)

Session Status                online
Version                       2.2.4
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://79ab83c9.ngrok.io -> localhost:8080
Forwarding                    https://79ab83c9.ngrok.io -> localhost:8080

Connections                   ttl     opn     rt1     rt5     p50     p90
                              24      0       0.00    0.01    0.00    0.00

3、 浏览器打开 Web入口http://127.0.0.1:4040.

4、此时如果使用其他设备访问Forwarding后面的地址,就会在Web页面上面查看到当前访问的请求细节.

ngrok-page

错误信息是因为没有注册授权

5、 sign up for an account in ngrok 获取ngrok的授权码,

6、 进行本机认证 Install your authtoken.

ngrok authtoken <YOUR_AUTHTOKEN>

7、设置外网的访问密码

// username 用户名 password密码 8080相关的端口
ngrok http -auth="username:password" 8080

8、 自定义子域名,(因为自动生成的会随机改变,如果想要固定访问域名地址,需要自定义), 这个功能需要付费!!!!!!!

// 举例,新开一个隧道,以`manajay` 为名称 ,后面跟Web端口
ngrok http -subdomain=manajay 8080

9、 自定义域名

ngrok-cname

  • 激活该域名
ngrok http -hostname=xxxx.com 8000

10、 关闭访问的监测

Disabling Inspection
ngrok http -inspect=false '端口号'

11、 强制访问网址为Http或者https

//http
ngrok http -bind-tls=false site.dev:80
// https
ngrok http -bind-tls=true  site.dev:80

常见的报错

1. 免费用户不能自定义域名与子域名
// Custom subdomain names
Failed to bind the custom subdomain 'manajay' for the account 'manajay'. This account is on the 'Free' plan.
// Tunnels on custom domains (white label URLs)
2. 设置访问密码
// auth出错
ngrok http -auth="username:password" 8080
//
Tunnel session failed: Your account '' is limited to 1 simultaneous ngrok client session.
Active ngrok client sessions in region 'us':
  - xxxxxx (xxxxx:58075)

参考链接

最近的文章

OCLint 静态代码分析

环境 Homebrew 终端安装 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" oclint 安装 brew install oclint xcpretty 安装 gem install xcpretty脚本 关键点 明确项目是否依赖CocoaPods 使用xcodebuild -list, 明确 scheme ...…

iOS自动化继续阅读
更早的文章

iOS 高效编码(一)

在类的头文件中尽量少运入其他头文件1、 除非有必要,否则不要引入头文件. 一般来说,应该在类的头文件中使用向前引用来声明一个类,并在实现文件中,引入那些类的头文件.好处: 减少编译时间,解决互相引用问题,降低类之间的耦合.2、 如果无法使用向前引用,比如声明某个类遵守一项协议.这种情况下,尽量把声明移到”class-continuation分类”中. 如果不行就把协议单独放在一个头文件中,然后将其引入.两者的区别在于: 协议与遵循协议类的关系,是否有强烈的依赖关系.比如委托协议(deleg...…

iOS编码继续阅读