网淘吧来吧,欢迎您!

Cloudflare API技能使用说明

2026-03-30 新闻来源:网淘吧 围观:12
电脑广告
手机广告

Cloudflare技能

连接至CloudflareAPI,用于DNS管理、隧道和区域管理。

设置

1. 获取您的API令牌

  1. 前往dash.cloudflare.com/profile/api-tokens
  2. 创建具有所需权限的令牌:
    • 区域:读取- 列出域名
    • DNS:编辑- 管理DNS记录
    • 账户:Cloudflare隧道:编辑- 管理隧道
  3. 复制令牌

2. 配置

# Option A: Store in file (recommended)
echo "YOUR_API_TOKEN" > ~/.cloudflare_token
chmod 600 ~/.cloudflare_token

# Option B: Environment variable
export CLOUDFLARE_API_TOKEN="YOUR_API_TOKEN"

3. 测试连接

./scripts/setup.sh

命令

区域(域名)

./scripts/zones/list.sh                    # List all zones
./scripts/zones/list.sh --json             # JSON output
./scripts/zones/get.sh example.com         # Get zone details

DNS记录

# List records
./scripts/dns/list.sh example.com
./scripts/dns/list.sh example.com --type A
./scripts/dns/list.sh example.com --name api

# Create record
./scripts/dns/create.sh example.com \
  --type A \
  --name api \
  --content 1.2.3.4 \
  --proxied

# Create CNAME
./scripts/dns/create.sh example.com \
  --type CNAME \
  --name www \
  --content example.com \
  --proxied

# Update record
./scripts/dns/update.sh example.com \
  --name api \
  --type A \
  --content 5.6.7.8

# Delete record
./scripts/dns/delete.sh example.com --name api --type A

隧道

# List tunnels
./scripts/tunnels/list.sh

# Create tunnel
./scripts/tunnels/create.sh my-tunnel

# Configure tunnel ingress
./scripts/tunnels/configure.sh my-tunnel \
  --hostname app.example.com \
  --service http://localhost:3000

# Get run token
./scripts/tunnels/token.sh my-tunnel

# Delete tunnel
./scripts/tunnels/delete.sh my-tunnel

令牌权限

功能所需权限
列出区域区域:读取
管理DNSDNS:编辑
管理隧道账户:Cloudflare隧道:编辑

创建令牌地址:dash.cloudflare.com/profile/api-tokens

Cloudflare API


常见工作流程

将子域名指向服务器

./scripts/dns/create.sh mysite.com --type A --name api --content 1.2.3.4 --proxied

为本地服务设置隧道

# 1. Create tunnel
./scripts/tunnels/create.sh webhook-tunnel

# 2. Configure ingress
./scripts/tunnels/configure.sh webhook-tunnel \
  --hostname hook.mysite.com \
  --service http://localhost:8080

# 3. Add DNS record
TUNNEL_ID=$(./scripts/tunnels/list.sh --name webhook-tunnel --quiet)
./scripts/dns/create.sh mysite.com \
  --type CNAME \
  --name hook \
  --content ${TUNNEL_ID}.cfargotunnel.com \
  --proxied

# 4. Run tunnel
TOKEN=$(./scripts/tunnels/token.sh webhook-tunnel)
cloudflared tunnel run --token $TOKEN

输出格式

标志描述
--jsonAPI返回的原始JSON
--table格式化表格(默认)
--quiet最小化输出(仅ID)

故障排除

错误解决方案
“未找到API令牌”运行设置或配置CLOUDFLARE_API_TOKEN
"401 未授权"检查令牌是否有效
"403 禁止访问"令牌缺少所需权限
"未找到区域"验证域名是否在您的账户中

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第326370名访客 今日有221篇新文章/评论