Cloudflare配置指南
Cloudflare(常拼写为 Cloudfare)是一个全球的云服务提供商,以其强大的边缘网络和安全防护能力著称。
2. 作用与核心能力
Section titled “2. 作用与核心能力”- 提供免费的 CDN 服务:加速全球用户的网站访问。
- 提供 DDoS 缓解与防护:保护源站免受大规模流量攻击。
- DNS 安全与管理:提供低延迟、高可用的智能 DNS 解析与 DNSSEC。
3. Worker 开发流程
Section titled “3. Worker 开发流程”Cloudflare Workers 是一个无服务器(Serverless)的轻量级计算平台,允许你在全球边缘节点上运行 JavaScript/TypeScript。
3.1. 安装 Wrangler CLI
Section titled “3.1. 安装 Wrangler CLI”Wrangler 是 Cloudflare 官方提供的 Workers 命令行开发工具。
npm i -G wrangler@latestwrangler -v3.2. 授权认证
Section titled “3.2. 授权认证”在本地开发或部署前,需要对 Wrangler 进行授权。
# 方式一: OAuth2.0wrangler login
# 方式二:Tokenexport CLOUDFLARE_API_TOKEN=""3.3. 初始化项目
Section titled “3.3. 初始化项目”wrangler init #初始化项目4. 部署配置 wrangler.jsonrc
Section titled “4. 部署配置 wrangler.jsonrc”# wrangler.jsonrc/** * For more details on how to configure Wrangler, refer to: * https://developers.cloudflare.com/workers/wrangler/configuration/ */{ "$schema": "node_modules/wrangler/config-schema.json", "name": "wechat-proxy", "main": "src/index.ts", "compatibility_date": "2025-08-12", // "vars": { // "AUTH": "123" // }, "observability": { "enabled": true }, "dev": { "port": 8000 } /** * Smart Placement * Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement */ // "placement": { "mode": "smart" } /** * Bindings * Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including * databases, object storage, AI inference, real-time communication and more. * https://developers.cloudflare.com/workers/runtime-apis/bindings/ */ /** * Environment Variables * https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables */ // "vars": { "MY_VARIABLE": "production_value" } /** * Note: Use secrets to store sensitive data. * https://developers.cloudflare.com/workers/configuration/secrets/ */ /** * Static Assets * https://developers.cloudflare.com/workers/static-assets/binding/ */ // "assets": { "directory": "./public/", "binding": "ASSETS" } /** * Service Bindings (communicate between multiple Workers) * https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings */ // "services": [{ "binding": "MY_SERVICE", "service": "my-service" }]}4.1. 部署项目
Section titled “4.1. 部署项目”wrangler deploy5. 内网服务
Section titled “5. 内网服务”Zero Trust -> 网络 -> Tunnel6. 拓展信息与限制
Section titled “6. 拓展信息与限制”- 边缘证书不支持三级域名
- wrangler login 授权无效
点击两边授权链接进行验证