部署到 Cloudflare Pages
Cloudflare Pages 提供全球 CDN 和免费的静态网站托管服务,是部署 Mizuki 博客的优秀选择。
通过网站 UI 部署
Section titled “通过网站 UI 部署”- 将你的代码推送到 GitHub 或 GitLab
- 登录 Cloudflare Dashboard
- 进入 Workers & Pages > Create > Pages > Connect to Git
- 选择你的仓库并配置以下设置:
- Framework preset: Astro
- Build command:
pnpm build - Build output directory:
dist
- 添加环境变量(可选):
NODE_VERSION:18或更高版本
- 点击 Save and Deploy
部署完成后,Cloudflare 会自动分配一个 *.pages.dev 域名。
使用 Wrangler CLI 部署
Section titled “使用 Wrangler CLI 部署”安装 Wrangler
Section titled “安装 Wrangler”pnpm add -g wrangler登录 Cloudflare
Section titled “登录 Cloudflare”wrangler login# 构建项目pnpm build
# 部署到 Cloudflare Pageswrangler pages deploy dist --project-name=mizuki-blog自定义域名配置
Section titled “自定义域名配置”- 进入 Cloudflare Pages 项目设置
- 选择 Custom domains
- 添加你的域名
- 按照提示配置 DNS 记录
环境变量配置
Section titled “环境变量配置”在 Cloudflare Pages 项目设置中可以配置环境变量:
- 进入项目 Settings > Environment variables
- 添加生产环境和预览环境的变量
常用环境变量:
| 变量名 | 说明 |
|---|---|
NODE_VERSION |
Node.js 版本 |
ENABLE_CONTENT_SYNC |
是否启用内容同步 |
CONTENT_REPO_URL |
内容仓库地址 |
Cloudflare Pages 会为每个非生产分支的推送自动创建预览部署,方便你在合并前测试更改。
部署到 Cloudflare Worker
Section titled “部署到 Cloudflare Worker”部署到worker,可以使用高级的自定义路由,适合将项目改造为全栈