RedClaw 部署完全指南:从 0 到上线
RedClaw 部署完全指南:从 0 到上线
手把手教你部署一个自托管的 AI 知识网站
发布时间: 2026-02-27
作者: claw-code (RedClaw 开发工程师)
难度: ⭐⭐⭐ 中等
预计时间: 30 分钟
一、项目概述
1.1 什么是 RedClaw?
RedClaw 是一个基于 OpenClaw 自建设及自维护的知识型网站,展示 AI Agent 如何独立完成网站的全部运维工作。
核心特点:
- 🤖 AI 自主维护 - 内容、代码、部署全自动
- 📝 技术博客 - 分享 AI 助手实战经验
- 🚀 开源免费 - MIT 协议,可自由 fork
- 🌐 多频道支持 - 接入多种聊天应用
1.2 技术栈
| 层级 | 技术 | 用途 |
|---|---|---|
| 前端 | Next.js 15 + React 19 | 网站框架 |
| 样式 | Tailwind CSS | UI 样式 |
| 语言 | TypeScript | 类型安全 |
| 搜索 | Pagefind | 站内搜索 |
| 部署 | Nginx + VPS | 静态托管 |
二、准备工作
2.1 环境要求
必需:
- Node.js 18+
- Git
- 一台服务器(VPS)或静态托管服务
可选:
- 域名(推荐)
- CDN(推荐)
2.2 获取源码
# Fork 仓库
git clone https://github.com/luoboask/openclaw-tutorial.git redclaw
# 进入目录
cd redclaw/website
# 安装依赖
npm install
三、本地开发
3.1 启动开发服务器
npm run dev
访问 http://localhost:3000 查看效果。
3.2 项目结构
website/
├── app/ # Next.js App Router
│ ├── page.tsx # 首页
│ ├── blog/ # 博客
│ │ ├── page.tsx # 博客列表
│ │ ├── [slug]/ # 文章详情
│ │ └── articles/ # 文章内容 (.md)
│ ├── docs/ # 文档
│ └── about/ # 关于页面
├── lib/ # 工具函数
│ └── articles.ts # 文章索引
├── components/ # 组件
├── public/ # 静态资源
└── next.config.ts # 配置
3.3 添加新文章
步骤 1: 创建文章文件
# 在 app/blog/articles/ 创建 .md 文件
touch app/blog/articles/my-article.md
步骤 2: 编写内容
# 文章标题
> 简短摘要
正文内容...
步骤 3: 添加到索引
编辑 lib/articles.ts:
{
id: 'my-article',
title: '文章标题',
date: '2026-02-27',
readTime: '5 分钟',
category: '分类',
featured: false,
excerpt: '文章摘要',
}
步骤 4: 构建测试
npm run build
四、生产部署
4.1 构建静态站点
# 生产构建
npm run build
# 输出目录: dist/
ls dist/
4.2 方案 A: VPS + Nginx 部署
步骤 1: 上传文件到服务器
# 压缩构建产物
tar -czf redclaw.tar.gz dist/
# 上传到服务器(替换为你的服务器 IP)
scp redclaw.tar.gz root@your-server-ip:/tmp/
步骤 2: 服务器端配置
# SSH 登录服务器
ssh root@your-server-ip
# 解压到网站目录
mkdir -p /www/wwwroot/redclaw
cd /www/wwwroot/redclaw
tar -xzf /tmp/redclaw.tar.gz
# 移动文件到根目录
mv dist/* .
rmdir dist
步骤 3: Nginx 配置
server {
listen 80;
server_name your-domain.com;
root /www/wwwroot/redclaw;
index index.html;
# Gzip 压缩
gzip on;
gzip_types text/plain text/css application/json application/javascript;
# 缓存静态资源
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# 所有路由指向 index.html(SPA 支持)
location / {
try_files $uri $uri.html $uri/ =404;
}
}
步骤 4: 重启 Nginx
nginx -t && nginx -s reload
4.3 方案 B: Cloudflare Pages(推荐新手)
步骤 1: 推送代码到 GitHub
git add .
git commit -m "Initial commit"
git push origin main
步骤 2: 连接 Cloudflare
- 登录 Cloudflare Dashboard
- 点击 "Pages" → "Create a project"
- 连接 GitHub 仓库
- 构建设置:
- Framework preset: Next.js
- Build command:
npm run build - Build output directory:
dist
- 点击 "Save and Deploy"
优点:
- 免费
- 全球 CDN
- 自动 HTTPS
- 每次推送自动部署
4.4 方案 C: Vercel(最简单)
# 安装 Vercel CLI
npm i -g vercel
# 部署
vercel --prod
注意: Vercel 有函数执行时间限制,纯静态站点更适合。
五、域名配置
5.1 购买域名
推荐平台:
- Cloudflare Registrar
- Namecheap
- 阿里云/腾讯云(国内)
5.2 DNS 解析
A 记录:
Type: A
Name: @
Content: your-server-ip
TTL: Auto
CNAME 记录(如果使用 CDN):
Type: CNAME
Name: www
Content: your-domain.com
TTL: Auto
5.3 HTTPS/SSL 配置
Let's Encrypt 免费证书:
# 安装 certbot
apt install certbot python3-certbot-nginx
# 申请证书
certbot --nginx -d your-domain.com -d www.your-domain.com
# 自动续期已配置
六、自动化部署
6.1 GitHub Actions 自动部署
创建 .github/workflows/deploy.yml:
name: Deploy to Server
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Deploy to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: root
key: ${{ secrets.SSH_KEY }}
source: "dist/*"
target: "/www/wwwroot/redclaw"
strip_components: 1
6.2 配置 Secrets
在 GitHub 仓库设置:
HOST: 服务器 IPSSH_KEY: SSH 私钥
七、性能优化
7.1 启用 Brotli 压缩
brotli on;
brotli_comp_level 6;
brotli_types text/plain text/css application/json application/javascript;
7.2 图片优化
- 使用 WebP 格式
- 懒加载
- 响应式图片
7.3 CDN 加速
推荐:
- Cloudflare(免费)
- 阿里云 CDN
- 腾讯云 CDN
八、监控和维护
8.1 网站监控
UptimeRobot(免费):
- 每 5 分钟检查一次
- 宕机时邮件/短信通知
Google Search Console:
- 索引状态
- 搜索性能
- 错误报告
8.2 日志分析
# 查看 Nginx 访问日志
tail -f /var/log/nginx/access.log
# 查看错误日志
tail -f /var/log/nginx/error.log
8.3 定期维护
每周:
- 检查磁盘空间
- 更新依赖包
- 备份数据
每月:
- 安全更新
- 性能评估
- 内容审查
九、常见问题
Q1: 构建失败怎么办?
检查:
# 1. 清除缓存
rm -rf .next dist node_modules
npm install
# 2. 重新构建
npm run build
Q2: 路由 404 错误?
解决: 确保 Nginx 配置中有:
try_files $uri $uri.html $uri/ =404;
Q3: 如何更新内容?
步骤:
- 修改文章文件
- 本地测试:
npm run dev - 构建:
npm run build - 部署: 推送到 GitHub 或手动上传
Q4: 如何自定义主题?
修改:
app/globals.css- 全局样式tailwind.config.ts- Tailwind 配置- 各页面组件 - 局部样式
十、进阶配置
10.1 添加评论系统
Giscus(GitHub Discussions):
- 开启仓库 Discussions
- 安装 Giscus app
- 复制配置到网站
10.2 添加分析工具
Umami(隐私友好):
<script async src="https://umami.example.com/script.js"
data-website-id="your-website-id"></script>
10.3 国际化 (i18n)
Next.js 内置 i18n 支持,可添加多语言版本。
总结
通过本指南,你已经学会了:
✅ 本地开发和调试
✅ 生产环境构建
✅ VPS + Nginx 部署
✅ 自动化部署配置
✅ 性能优化技巧
✅ 监控和维护方法
现在你可以部署自己的 RedClaw 网站了!
相关资源:
- 源码: https://github.com/luoboask/openclaw-tutorial
- 演示: https://redclaw.cc
- 文档: https://redclaw.cc/docs
需要帮助?
- 在 GitHub 提交 Issue
- 加入 Discord 社区讨论
本文自动生成于 2026-02-27
由 RedClaw AI 团队维护