← 返回首页
如何利用 OpenClaw 部署自己的博客
从零开始,使用 OpenClaw + Next.js + Tailwind CSS 快速搭建并部署个人博客,支持 HTTPS、自动续期、生产环境配置
2026年3月14日
OpenClawNext.js部署教程博客搭建
如何利用 OpenClaw 部署自己的博客
💡 本文适合人群:想要快速搭建个人博客的开发者,无需深入了解复杂配置,OpenClaw 帮你自动化完成。
📋 前言
你是否想过拥有一个自己的技术博客,但被各种配置劝退?今天我来分享如何用 OpenClaw 快速部署一个现代化的个人博客。
技术栈:
- Next.js 16(React 全栈框架)
- Tailwind CSS(原子化 CSS)
- Nginx(反向代理)
- Let's Encrypt(免费 HTTPS)
- PM2(进程管理)
最终效果:一个支持 HTTPS、自动续期证书、生产级别的博客系统。
🚀 第一步:环境准备
1.1 服务器要求
- Linux 服务器(我的是 OpenCloudOS)
- Node.js 18+
- Nginx
- 已备案的域名(我的是
blog.jiance168.com)
1.2 安装 Node.js
# 使用 nvm 安装 Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 22
nvm use 22
1.3 安装 OpenClaw
npm install -g openclaw
📦 第二步:创建 Next.js 项目
2.1 初始化项目
npx create-next-app@latest my-blog --typescript --tailwind --app
cd my-blog
2.2 安装博客必需依赖
npm install gray-matter remark remark-html lucide-react
依赖说明:
gray-matter:解析 Markdown frontmatterremark:Markdown 渲染lucide-react:图标库
📁 第三步:项目结构
3.1 创建目录
mkdir -p content/posts
mkdir -p lib
3.2 创建工具函数 lib/posts.ts
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
const postsDirectory = path.join(process.cwd(), 'content/posts');
export function getSortedPostsData() {
const fileNames = fs.readdirSync(postsDirectory);
const allPostsData = fileNames.map(fileName => {
const slug = fileName.replace(/\.md$/, '');
const fullPath = path.join(postsDirectory, fileName);
const fileContents = fs.readFileSync(fullPath, 'utf8');
const matterResult = matter(fileContents);
return {
slug,
...(matterResult.data as { title: string; date: string; description: string; tags: string[] }),
};
});
return allPostsData.sort((a, b) => (a.date < b.date ? 1 : -1));
}
export function getPostData(slug: string) {
const fullPath = path.join(postsDirectory, `${slug}.md`);
const fileContents = fs.readFileSync(fullPath, 'utf8');
const matterResult = matter(fullPath);
return {
slug,
content: matterResult.content,
...(matterResult.data as { title: string; date: string; description: string; tags: string[] }),
};
}
✍️ 第四步:创建第一篇文章
在 content/posts/ 目录创建 .md 文件即可。
🎨 第五步:设计页面
主页展示文章列表,文章详情页使用动态路由。
🔧 第六步:使用 OpenClaw 部署
6.1 构建生产版本
npm run build
6.2 使用 PM2 启动服务
npm install -g pm2
pm2 start npm --name blog -- start
pm2 save
pm2 startup
6.3 配置 Nginx
创建 /etc/nginx/conf.d/blog.yourdomain.com.conf,配置反向代理到本地 3000 端口。
6.4 申请 SSL 证书
certbot certonly --webroot -w /usr/share/nginx/html -d blog.yourdomain.com
✅ 第七步:验证部署
pm2 status blog
curl -I https://blog.yourdomain.com
📝 总结
通过 OpenClaw + Next.js,你可以在 30 分钟内 搭建一个生产级别的博客系统:
✅ 现代化设计(Tailwind CSS)
✅ SEO 优化(Next.js 元数据)
✅ HTTPS 安全(Let's Encrypt)
✅ 自动部署(PM2 + Nginx)
✅ 易于维护(Markdown 写作)
希望这篇教程对你有帮助! 🎉