注意⚠️:以下操作仅适用于mac os系统,实测主机os版本为15.6
使用brew安装local client
brew install cloudflared
方式一:使用免费的随机域名
建立快速随机通道,url后为本地服务地址(具体到端口)
cloudflared tunnel --protocol http2 --url http://127.0.0.1:8787 (base)
方式二: 使用自有域名
A. 网页端操作
- 在cloudflare中进入 Networks -> Connectors,创建一个tunnel

- 配置路由信息

B. 本地(终端)操作
本地登陆,认领tunnel
cloudflared tunnel login使用http2运行localclient
# 方式一: 自启动服务,开机自动建立tunnel sudo cloudflared --protocol http2 service install 在cloudflare中获取的对应tunnel的token # 方式二: 手工启动(每次需要运行该命令才建立tunnel) cloudflared tunnel run --token yourtoken查看http2配置是否生效,未生效修改后重启即可。
# 查看local client配置的命令
cat /Library/LaunchDaemons/com.cloudflare.cloudflared.plist
#检查<array></array>间是否包含http2 、--portocol
<array>
<string>/opt/homebrew/bin/cloudflared</string>
<string>tunnel</string>
<string>run</string>
<string>--protocol</string>
<string>http2</string>
</array>
#修改文件命令,一般使用nano
sudo nano /Library/LaunchDaemons/com.cloudflare.cloudflared.plist
# 以下两个命令用于修改配置后强制重载配置并重启客户的服务
# 1. 彻底从系统服务清单中剔除
sudo launchctl bootout system /Library/LaunchDaemons/com.cloudflare.cloudflared.plist
# 2. 重新压入并立即启动
sudo launchctl bootstrap system /Library/LaunchDaemons/com.cloudflare.cloudflared.plist
