cloudflared 是 Cloudflare 提供的一个轻量级命令行工具,允许你通过 Cloudflare Tunnel(原 Argo Tunnel) 将本地服务暴露在公网,且免费提供 HTTPS 域名(如 https://xxx.trycloudflare.com)进行访问。
🧰一、安装cloudflared✅方法一:使用官方安装脚本(Linux/macOS)bash
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared
chmod +x cloudflared
sudo mv cloudflared /usr/local/bin/
✅方法二:macOS(使用 Homebrew)bash
brew install cloudflared
✅方法三:Windows 用户下载地址:👉https://github.com/cloudflare/cloudflared/releases下载.exe文件后,放到系统环境变量路径或直接执行。🚀二、快速使用cloudflared暴露本地服务🌐例如你本地有一个服务运行在端口8080:bash
cloudflared tunnel --url http://localhost:8080输出示例:css
INFO[0000] Route propagating, it may take up to 1 minute
INFO[0001] Connection established
...
https://subdomain.trycloudflare.com🔗你可以立即通过该地址访问本地服务
🛡️三、安全增强用法(可选)🔐登录 Cloudflare 账号(使用自定义域名时)bash
cloudflared tunnel login
📁创建持久化隧道(推荐用于长期服务)bash
cloudflared tunnel create my-tunnel
并配置config.yml,示例如下:yaml
tunnel: my-tunnel
credentials-file: /home/user/.cloudflared/my-tunnel.json
ingress:
hostname: example.yourdomain.com
service: http://localhost:8080
service: http_status:404
📦四、Docker 中使用bash
docker run -it --rm \
cloudflare/cloudflared:latest \
tunnel --url http://host.docker.internal:8080
📘五、用途场景
•本地开发 HTTPS 隧道,便于微信/支付宝/Stripe 等 Webhook 测试
•临时公网共享页面
•搭建远程内网穿透服务替代 ngrok、frp
•持久化部署到 VPS 上做反向代理
启动 tunnel
cloudflared tunnel --url http://localhost:8081
你会看到一段输出类似于:
2025-07-29T11:00:00Z INF Requesting new quick Tunnel on trycloudflare.com...
2025-07-29T11:00:01Z INF + https://unrealistic-cow.trycloudflare.com
评论功能已关闭
该文章不允许评论