跳转到内容

Cloudflare配置指南

Cloudflare(常拼写为 Cloudfare)是一个全球的云服务提供商,以其强大的边缘网络和安全防护能力著称。


  • 提供免费的 CDN 服务:加速全球用户的网站访问。
  • 提供 DDoS 缓解与防护:保护源站免受大规模流量攻击。
  • DNS 安全与管理:提供低延迟、高可用的智能 DNS 解析与 DNSSEC。

Cloudflare Workers 是一个无服务器(Serverless)的轻量级计算平台,允许你在全球边缘节点上运行 JavaScript/TypeScript。

Wrangler 是 Cloudflare 官方提供的 Workers 命令行开发工具。

Terminal window
npm i -G wrangler@latest
wrangler -v

在本地开发或部署前,需要对 Wrangler 进行授权。

Terminal window
# 方式一: OAuth2.0
wrangler login
# 方式二:Token
export CLOUDFLARE_API_TOKEN=""
Terminal window
wrangler init #初始化项目

# 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" }]
}
Terminal window
wrangler deploy

Zero Trust -> 网络 -> Tunnel

  • 边缘证书不支持三级域名
  • wrangler login 授权无效
点击两边授权链接进行验证