准备工作:
一个cloudflare.com的账号,注册地址https://dash.cloudflare.com/login ,有一个域名(例如:www.baidu.com)
linux系统 arm、arm64、x86、amd64平台都可以。
开始部署:
1.下载程序到盒子里:
wget https://github.com/cloudflare/cloudflared/releases/download/2022.5.1/cloudflared-linux-arm -O /usr/bin/cloudflared
上面命令如果下载失败可到 https://github.com/cloudflare/cloudflared/releases 对应版本下载,32位arm平台选择【cloudflared-linux-arm】hi3798mv100也选这个
2.cloudflare授权 #非root用户请在前面加上 sudo
chmod -R 0777 /usr/bin/cloudflared
cloudflared login
此时终端会显示一个https:// 的网址,复制到浏览器打开,登录自己的cloudflare账号,选择要绑定的域名,并获取自动下载的授权文件
3.创建隧道
例如
cloudflared tunnel create web #web 是你创建的隧道名称,记好,后面要用,这个名称可自定义
得到隧道的id
4.自制配置文件config.yml
vi config.yml
例如:
tunnel:xxxx-xxxx-你的ID-xxxx-xxxx
credentials-file: /root/.cloudflared/xxxx-xxxx-你的ID-xxxx-xxxx.json
ingress:
- hostname: www.baidu.com
service: http://127.0.0.1 - service: http_status:404
上面 hostname后面的 www.baidu.com 中 www是二级域名名称,baidu.com 是顶级域名
(也就是你在cloudflared关联的域名)
service: http://127.0.0.1 这是外网https穿透访问的页面地址,可加端口如http://127.0.0.1:88
(请先保证此页面在内网中http可访问)
把这个配置文档放置到/etc/cloudflared/下面
修改编辑完毕, 按一次 Esc 按键退出编辑模式,
然后输入 :wq , 回车即可保存并退出文档
5.在终端输入
mkdir -p /etc/cloudflared/
cp config.yml /etc/cloudflared/
cloudflared tunnel route dns web www.baidu.com
上面命令中web是指前面创建的隧道名称,www.baidu.com是前面config.yml文件中配置的二级域名。
6.运行自启动安装
cloudflared service install #运行自启动安装
systemctl start cloudflared #启动服务
systemctl status cloudflared #查看运行状态 可随时ctrl + c 中止。
tunnel: f0190432-03a9-4bf0-a53a-464b2de6ddd0
credentials-file: /root/.cloudflared/f0190432-03a9-4bf0-a53a-464b2de6ddd0.json
ingress:
- hostname: www.1771.tk
service: http://192.168.0.105 - hostname: p.1771.tk
service: http://192.168.0.105:5244 - hostname: l.1771.tk
service: http://192.168.0.105:5700 - hostname: rw.1771.tk
service: http://192.168.0.105:6008 - hostname: ms.1771.tk
service: http://192.168.0.105:10888 - hostname: bt.1771.tk
service: http://192.168.0.105:9091 - service: http_status:404
评论 (0)