用 Hexo + Cloudflare Pages 搭建个人博客:完整指南

用 Hexo + Cloudflare Pages 搭建个人博客:完整指南

Ren Echo Lv4

前言

想拥有一个属于自己的博客?不想花一分钱?还能在国内快速访问?

这篇文章记录了我用 Hexo + Redefine 主题 + Cloudflare Pages 搭建 Ren Echo 博客的完整过程,从零到上线只需 30 分钟。

为什么选这个方案?

方案 国内速度 免费 自动部署 上手难度
WordPress ❌(需服务器) 中等
GitHub Pages ❌ 慢 ❌ 手动 简单
Vercel ❌ 部分被墙 简单
Cloudflare Pages ✅ 较快 简单

技术栈

  • 框架:Hexo(Node.js 静态博客生成器)
  • 主题:Redefine(现代、美观、功能丰富)
  • 部署:Cloudflare Pages(全球 CDN、自动构建)
  • 源码托管:GitHub

搭建步骤

第一步:安装环境

确保电脑上安装了 Node.js(>= 20)和 Git:

1
2
node -v   # 确认 Node.js 版本
git --version # 确认 Git 版本

第二步:初始化 Hexo 项目

1
2
3
4
npm install -g hexo-cli
hexo init blog
cd blog
npm install

第三步:安装 Redefine 主题

1
npm install hexo-theme-redefine

修改根目录 _config.yml

1
theme: redefine

第四步:创建主题配置文件

在项目根目录创建 _config.redefine.yml,配置你的博客信息(标题、导航栏、侧边栏等)。

第五步:本地预览

1
2
npx hexo server
# 浏览器打开 http://localhost:4000

第六步:部署到 Cloudflare Pages

  1. 将源码推到 GitHub
  2. 登录 Cloudflare Dashboard
  3. 创建 Pages 项目,关联 GitHub 仓库
  4. 构建设置:
    • Build command: npx hexo generate
    • Build output directory: public
    • 环境变量: NODE_VERSION = 20
  5. 点击 Deploy,等待 30 秒

第七步:日常发文

1
2
3
4
5
6
npx hexo new "文章标题"
# 编辑 source/_posts/文章标题.md
git add .
git commit -m "发布新文章"
git push
# Cloudflare 自动构建,1 分钟内上线

常用命令

1
2
3
4
npx hexo new "标题"      # 新建文章
npx hexo server # 本地预览
npx hexo generate # 生成静态文件
npx hexo clean # 清除缓存

踩坑记录

  1. 构建失败:检查 NODE_VERSION 环境变量是否设为 20
  2. 样式丢失:确认 _config.yml 中的 url 是你的实际域名
  3. 图片不显示:建议使用图床,或者开启 post_asset_folder

总结

Hexo + Cloudflare Pages 是目前性价比最高的博客方案:免费、快速、自动部署。搭配 Redefine 主题,颜值也在线。

如果你也想搭建一个个人博客,不妨试试这个方案!


相关文章:博客开张:Hello, Ren Echo!

  • 标题: 用 Hexo + Cloudflare Pages 搭建个人博客:完整指南
  • 作者: Ren Echo
  • 创建于 : 2026-05-28 16:00:00
  • 更新于 : 2026-06-27 10:06:11
  • 链接: https://renecho-blog.pages.dev/2026/05/28/hexo-cloudflare-guide/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论