📊 2026 年更新:Hexo 博客完整部署指南
原文内容整理
服务器配置:
- 配置 nginx 证书,转向本地 frp 转内网端口
- 内网 kng1 91
- frpc 内网端口转向各自服务
参考资源:
🚀 Hexo 博客部署完全指南(2026 年)
一、Hexo 简介
Hexo 是一款快速、简洁且高效的博客框架,基于 Node.js 开发。
特点:
- ✅ 极速生成(< 1 秒生成百篇文章)
- ✅ 支持 Markdown
- ✅ 一键部署到 GitHub/码云
- ✅ 丰富的主题生态
- ✅ 静态网站(安全、快速)
适用场景:
- 📝 个人博客
- 📚 技术文档
- 📖 产品手册
- 💼 企业官网
二、环境准备
2.1 系统要求
| 组件 |
版本 |
用途 |
| Node.js |
14.0+ |
运行环境 |
| npm |
6.0+ |
包管理 |
| Git |
2.0+ |
版本控制 |
| Hexo |
5.0+ |
博客框架 |
2.2 安装步骤
Windows/Mac:
1 2 3 4 5 6 7 8 9 10 11 12
| https://nodejs.org/
node -v npm -v
npm install -g hexo-cli
hexo -v
|
Linux(Ubuntu/Debian):
1 2 3 4 5 6 7 8 9 10 11 12
| curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt-get install -y nodejs
sudo apt-get install -y git
sudo npm install -g hexo-cli
hexo -v
|
三、创建博客
3.1 初始化博客
1 2 3 4 5 6 7 8 9 10 11 12 13
| hexo init my-blog
cd my-blog
npm install
hexo server
|
3.2 目录结构
1 2 3 4 5 6 7 8 9 10 11
| my-blog/ ├── _config.yml # 站点配置文件 ├── package.json # 依赖配置 ├── scaffolds/ # 模板文件 ├── source/ # 源文件 │ ├── _posts/ # 文章目录 │ ├── _drafts/ # 草稿目录 │ ├── tags/ # 标签页 │ └── categories/ # 分类页 ├── themes/ # 主题目录 └── public/ # 生成的静态文件
|
四、配置博客
4.1 站点配置(_config.yml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| title: 我的博客 subtitle: 记录技术成长 description: 专注于前端开发、DevOps、AI 技术 keywords: 前端,DevOps, AI, 技术博客 author: John language: zh-CN timezone: Asia/Shanghai
url: https://yourdomain.com root: / permalink: :year/:month/:day/:title/ permalink_defaults:
source_dir: source public_dir: public tag_dir: tags archive_dir: archives category_dir: categories
new_post_name: :title.md default_layout: post auto_spacing: false titlecase: false external_link: true max_open_file: 100 multi_thread: true filename_case: 0 render_drafts: false post_asset_folder: false relative_link: false future: true highlight: enable: true line_number: true auto_detect: false tab_replace: ''
index_generator: path: '' per_page: 10 order_by: -date
archive_generator: per_page: 0 yearly: true monthly: true daily: false
deploy: type: git repo: https://github.com/yourusername/yourusername.github.io.git branch: main
|
4.2 主题配置
推荐主题:
| 主题 |
特点 |
难度 |
| Next |
简洁优雅 |
⭐ |
| Butterfly |
功能丰富 |
⭐⭐ |
| Fluid |
响应式 |
⭐ |
| Icarus |
专业文档 |
⭐⭐⭐ |
安装 Next 主题:
1 2 3 4 5 6 7 8 9
| git clone https://github.com/next-theme/hexo-theme-next themes/next
vim _config.yml
hexo clean && hexo server
|
五、写作指南
5.1 创建文章
1 2 3 4 5 6 7 8
| hexo new post "文章标题"
hexo new draft "草稿标题"
hexo publish draft "草稿标题"
|
5.2 Front Matter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| --- title: 文章标题 date: 2026-03-07 12:00:00 updated: 2026-03-07 12:00:00 author: John categories: - 技术 - 前端开发 tags: - JavaScript - Vue description: 文章描述 keywords: Vue, JavaScript, 前端 cover: /images/cover.jpg draft: false ---
# 文章正文
这里是内容...
|
5.3 常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| hexo generate
hexo g
hexo server
hexo s
hexo clean
hexo deploy
hexo d
hexo generate && hexo deploy
hexo g -d
|
六、自动化部署
6.1 GitHub Pages 部署
步骤 1: 创建仓库
1
| https://github.com/yourusername/yourusername.github.io
|
步骤 2: 配置部署
1 2 3 4 5
| deploy: type: git repo: https://github.com/yourusername/yourusername.github.io.git branch: main
|
步骤 3: 安装插件
1
| npm install hexo-deployer-git --save
|
步骤 4: 部署
6.2 码云 Gitee 部署
步骤 1: 创建仓库
1
| https://gitee.com/yourusername/yourusername.gitee.io
|
步骤 2: 配置部署
1 2 3 4 5 6 7
| deploy: type: git repo: https://github.com/yourusername/yourusername.github.io.git: github https://gitee.com/yourusername/yourusername.gitee.io.git: gitee branch: main
|
步骤 3: 部署到双平台
6.3 Jenkins 自动化部署
Jenkinsfile 示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| pipeline { agent any stages { stage('拉取代码') { steps { git branch: 'main', url: 'https://github.com/yourusername/blog.git' } } stage('安装依赖') { steps { sh 'npm install' } } stage('生成静态文件') { steps { sh 'hexo generate' } } stage('部署到服务器') { steps { sh ''' rsync -avz --delete public/ user@server:/var/www/html/ ''' } } } }
|
七、Docker 部署
7.1 Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| FROM node:18-alpine
WORKDIR /app
RUN npm install -g hexo-cli
COPY . /app
RUN npm install
RUN hexo generate
FROM nginx:1.27-alpine
COPY --from=0 /app/public /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
|
7.2 Docker Compose
1 2 3 4 5 6 7 8 9 10 11
| version: '3.8'
services: hexo: build: . ports: - "8080:80" volumes: - ./source/_posts:/app/source/_posts - ./themes:/app/themes restart: unless-stopped
|
7.3 部署命令
1 2 3 4 5 6 7 8
| docker build -t hexo-blog .
docker run -d -p 8080:80 --name hexo-blog hexo-blog
docker-compose up -d
|
八、内网穿透部署(FRP)
8.1 服务端配置(frps.ini)
1 2 3 4 5 6 7 8 9
| [common] bind_port = 7000 dashboard_port = 7500 token = your_token dashboard_user = admin dashboard_pwd = admin_password
vhost_http_port = 80 vhost_https_port = 443
|
8.2 客户端配置(frpc.ini)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [common] server_addr = your_server_ip server_port = 7000 token = your_token
[hexo_blog] type = http local_port = 4000 custom_domains = blog.yourdomain.com
[hexo_admin] type = http local_port = 4000 custom_domains = admin.yourdomain.com
|
8.3 启动 FRP
1 2 3 4 5
| ./frps -c frps.ini
./frpc -c frpc.ini
|
九、性能优化
9.1 生成速度优化
问题:文章多了生成慢
解决方案:
1 2 3 4 5 6 7 8
|
syntax_highlighter: false
skip_render: - README.md - .gitignore
|
使用增量构建:
1 2 3 4 5 6 7
| npm install hexo-generator-archive --save
hexo generate --incremental
hexo g -i
|
9.2 访问速度优化
1. CDN 加速:
1 2 3 4
| cdn: enable: true provider: cloudflare
|
2. 图片优化:
1 2 3 4 5 6 7
| npm install hexo-image-compress --save
image_compress: enable: true quality: 80
|
3. 启用缓存:
十、SEO 优化
10.1 站点地图
1 2 3 4 5 6 7 8 9
| npm install hexo-generator-sitemap --save
sitemap: path: sitemap.xml rel: false tags: false categories: false
|
10.2 搜索引擎提交
Google Search Console:
- 验证网站所有权
- 提交 sitemap.xml
- 监控索引状态
百度搜索资源平台:
- 验证网站
- 提交 sitemap.xml
- 使用 API 推送
1 2 3 4 5 6 7
| open_graph: enable: true twitter_id: your_twitter google_plus: your_google_plus fb_admins: your_fb_admins fb_app_id: your_fb_app_id
|
十一、常见问题
Q1: 生成失败怎么办?
解决方案:
1 2 3 4 5 6 7 8 9 10 11
| hexo clean
rm -rf node_modules package-lock.json
npm install
hexo generate
|
Q2: 部署失败怎么办?
检查项:
- ✅ Git 配置正确
- ✅ SSH key 已添加
- ✅ 仓库权限正确
- ✅ 网络连接正常
调试命令:
1 2 3 4 5
| hexo deploy --debug
git clone https://github.com/yourusername/yourusername.github.io.git
|
Q3: 如何迁移文章?
从 WordPress 迁移:
1 2 3 4 5 6 7 8
| npm install hexo-migrator-wordpress --save
hexo migrate wordpress wordpress.xml
|
从 Jekyll 迁移:
1 2 3 4 5
| npm install hexo-migrator-jekyll --save
hexo migrate jekyll /path/to/jekyll
|
Q4: 如何备份博客?
方案 1: Git 备份
1 2 3 4 5 6 7 8 9 10 11
| git init
git add .
git commit -m "backup: $(date +%Y-%m-%d)"
git push origin main
|
方案 2: 云盘备份
1 2 3 4 5
| rsync -avz /path/to/blog /path/to/Dropbox/blog-backup
rclone sync /path/to/blog gdrive:blog-backup
|
📈 2026 年 Hexo 生态
流行主题
| 主题 |
Stars |
下载量 |
推荐指数 |
| Next |
20k+ |
100 万+ |
⭐⭐⭐⭐⭐ |
| Butterfly |
8k+ |
50 万+ |
⭐⭐⭐⭐⭐ |
| Fluid |
5k+ |
30 万+ |
⭐⭐⭐⭐ |
| Icarus |
4k+ |
20 万+ |
⭐⭐⭐⭐ |
常用插件
| 插件 |
用途 |
推荐指数 |
| hexo-deployer-git |
Git 部署 |
⭐⭐⭐⭐⭐ |
| hexo-generator-sitemap |
站点地图 |
⭐⭐⭐⭐⭐ |
| hexo-image-compress |
图片压缩 |
⭐⭐⭐⭐ |
| hexo-wordcount |
字数统计 |
⭐⭐⭐⭐ |
| hexo-related-popular-posts |
相关文章 |
⭐⭐⭐⭐ |
总结
Hexo 博客部署关键点:
✅ 环境:Node.js 18+、Git、Hexo CLI
✅ 配置:_config.yml、主题配置
✅ 写作:Front Matter、Markdown
✅ 部署:GitHub Pages/码云/Jenkins
✅ 优化:性能优化、SEO 优化
推荐方案:
- 🚀 个人博客:GitHub Pages + Next 主题
- 💼 企业官网:Jenkins 自动化部署
- 🔒 内网环境:FRP 内网穿透 + Docker
最后更新: 2026-03-07
标签: #Hexo #博客部署 #自动化部署 #Jenkins #Docker #FRP #静态网站
分类: 技术/DevOps/博客搭建