Mac下创建Cloudflare的Zero Trust通道连接器

1、安装Cloudflare服务

brew install cloudflared

cloudflared --version
查看版本信息

cloudflared version 2026.3.0 (built 2026-03-06T12:53:40Z)


2、cloudflare进行登陆授权
浏览器先登陆需要创建Zero连接器的Cloudflare账号

命令行中运行:

cloudflared login


在弹出的浏览器中,选择记录进行授权

3、检查环境变量,如果有临时代理,先取消

env | grep -i proxy
如果返回:
http_proxy=http://127.0.0.1:7890
https_proxy=http://127.0.0.1:7890

则说明有临时代理,执行下面命令进行取消:
unset http_proxy=http://127.0.0.1:7890
unset https_proxy=http://127.0.0.1:7890

4、查看现有tunnel删除多余的记录

cloudflared tunnel list

cloudflared tunnel delete <TUNNEL的ID或Name>


5、创建tunnel连接器

cloudflared tunnel create test

创建成功后,记住tunnel的ID,如:cc442e80-95be-4fe3-a890-ff30938474361


6、在~/.cloudflared路径下创建config.yml配置文件

frank@bogon ~ % vi ~/.cloudflared/config.yml


tunnel: test
credentials-file: /Users/frank/.cloudflared/cc442e80-95be-4fe3-a890-ff30938474361.json

ingress:
  - hostname: test.frank2000.uk
    service: http://localhost:3000
  - service: http_status:404

保存并退出!

7、获取test这个连接器的token

cloudflared tunnel token test

命令执行完毕后展示的一长串字符就是这个名为test连接器的token
如:eyJhIjoiMzBjNjgxNGZiMGNkMjIzYTY0NzIyM2JiODc2ZGY2MGUiLCJzIjoiTTJRNU9HWXhOREV0TVdRME5TMDBNalk1TFdJMk56a3R****VMk1EVm1ZV1E1IiwidCI6ImNjNDQyZTgwLTk1YmUtNGY0My1hODQ5LWZmMDc4NTc5NDcxMCJ9

8、创建域名绑定的命令(当前域名必须在这个cloudflare账号下)

cloudflared tunnel  route  dns  test  test.frank2000.uk

9、运行启动tunnel的命令

cloudflared tunnel run --token eyJhIjoiMzBjNjgxNGZiMGNkMjIzYTY0NzIyM2JiODc2ZGY2MGUiLCJzIjoiTTJRNU9HWXhOREV0TVdRME5TMDBNalk1TFdJMk56a3R****VMk1EVm1ZV1E1IiwidCI6ImNjNDQyZTgwLTk1YmUtNGY0My1hODQ5LWZmMDc4NTc5NDcxMCJ9

或者运行

cloudflared --config ~/.cloudflared/config.yml tunnel run test


10、命令行启动next.js项目

浏览器访问tunnel绑定的域名即可

https://test.frank2000.uk/


---------------------------------

有些连接器服务是开机自动启动的,要删除处于运行状态的连接器,要先停掉服务(再删除),可以执行下面的操作:

sudo pkill cloudflared


再执行连接器的删除:

cloudflared tunnel delete 8b5abec3-2644-4dad-b35f-b236bcb197b2





评论

此博客中的热门博文

通过命令行在Github上发布项目的新版本

利用GitHub免费的静态页面托管空间发布网页

本地部署OpenAvatarChat实时交互数字人系统