起因
一直想搭一个自己的博客,选了 Fuwari 这个 Astro 静态博客主题。服务器是阿里云 ECS(1.8G 内存),但是本地构建需要 7G+ 内存,服务器直接 pnpm build 会 OOM。所以需要一套 GitHub Actions 自动构建 + 部署的流程。
环境一览
| 项目 | 详情 |
|---|---|
| 博客框架 | Fuwari (Astro) |
| 代码托管 | GitHub (RunRunxka/Fuwari) |
| 服务器 | 阿里云 ECS,Alibaba Linux 8,IP x.x.x.x |
| 部署方式 | GitHub Actions 构建 → rsync 推送 → Python HTTP Server |
| 访问地址 | http://x.x.x.x:5544 |
第一步:服务器端准备
安装 rsync
服务器默认没装 rsync,GitHub Actions 推送文件要用到:
sudo yum install -y rsync配置 SSH 密钥
让 GitHub Actions 能 SSH 到服务器:
ssh-keygen -t ed25519 -f ~/.ssh/github_actions -N ""cat ~/.ssh/github_actions.pub >> ~/.ssh/authorized_keys私钥 ~/.ssh/github_actions 的内容后面要填到 GitHub Secrets。
第二步:GitHub Actions 工作流
在仓库根目录创建 .github/workflows/deploy.yml:
name: Build & Deploy
on: push: branches: [main] workflow_dispatch:
jobs: build-and-deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4 with: node-version: 22 cache: pnpm
- run: pnpm install --frozen-lockfile - run: pnpm build
- name: Deploy to server uses: easingthemes/ssh-deploy@v6.0.3 with: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} ARGS: "-rlgoDzvc --delete" SOURCE: "dist/" REMOTE_HOST: ${{ secrets.REMOTE_HOST }} REMOTE_USER: ${{ secrets.REMOTE_USER }} TARGET: "/home/admin/blog"设置 GitHub Secrets
去仓库 Settings → Secrets and variables → Actions,新建三个:
| Name | Value |
|---|---|
SSH_PRIVATE_KEY | ~/.ssh/github_actions 私钥内容 |
REMOTE_HOST | x.x.x.x |
REMOTE_USER | admin |
第三步:启动静态文件服务
构建好的文件在 /home/admin/blog/,用 Python 起个 HTTP 服务:
cd /home/admin/blog && python3 -m http.server 5544 --bind 0.0.0.0 &踩坑:80 端口被 nginx 占用
阿里云 ECS 默认装了 nginx 占着 80 端口。本来想用 80 方便直接 IP 访问,结果访问显示 nginx 欢迎页。改成 5544 端口解决。
注意:每次加新端口都要去阿里云安全组放行!
第四步:自定义博客
修改站点配置
编辑 src/config.ts:
export const siteConfig: SiteConfig = { title: "你的博客名", subtitle: "副标题", lang: "zh_CN", // ...};修改头像和个人信息
export const profileConfig: ProfileConfig = { avatar: "/touxiang.png", // 放 public/ 下避免哈希 name: "你的名字", bio: "个人简介", links: [ { name: "GitHub", icon: "fa6-brands:github", url: "https://github.com/xxx" }, ],};踩坑:头像加载不出
原来路径写 assets/images/touxiang.png,构建时 Astro 会将其哈希重命名为 _astro/touxiang.XXXX.png,但页面仍引用原路径导致 404。
两种解法:
- 移到
public/目录,路径写/touxiang.png(不会被哈希) - 在
config.ts里用import引入,然后添加env.d.ts类型声明
创建文章
直接在 src/content/posts/ 下建文件夹:
src/content/posts/├── my-post/│ ├── index.md│ └── cover.jpgindex.md 示例:
---title: 文章标题published: 2026-05-22description: 简介image: ./cover.jpgtags: [标签1, 标签2]category: 分类draft: false---
正文内容...第五步:域名(可选)
买了域名 runrunxka.xyz,去阿里云云解析加两条 A 记录:
| 主机记录 | 记录类型 | 记录值 |
|---|---|---|
@ | A | x.x.x.x |
www | A | x.x.x.x |
但国内服务器用域名需要 ICP 备案,否则访问被拦截提示 Non-compliance ICP Filing。暂时用 IP:端口方式访问。
总结
现在每次写完文章或改配置,只需要:
git add . && git commit -m "更新" && git pushGitHub Actions 自动构建并推送到服务器,一分钟内生效。全程不用碰服务器。
整个流程踩了几个坑:
easingthemes/ssh-deploy要用@v6.0.3,@v5不存在- 服务器必须先装 rsync
- 头像路径别用
src/assets/,用public/或 import - 国内服务器域名要备案
- 别用 80 端口,ECS 默认 nginx 占着
希望对同样折腾 Fuwari 的朋友有帮助 🚀
第一步:服务器端准备
安装 rsync
服务器默认没装 rsync,GitHub Actions 推送文件要用到:
sudo yum install -y rsync
配置 SSH 密钥
让 GitHub Actions 能 SSH 到服务器:
ssh-keygen -t ed25519 -f ~/.ssh/github_actions -N ""
cat ~/.ssh/github_actions.pub >> ~/.ssh/authorized_keys
私钥 ~/.ssh/github_actions 的内容后面要填到 GitHub Secrets。
第二步:GitHub Actions 工作流
在仓库根目录创建 .github/workflows/deploy.yml:
name: Build & Deployon: push: branches: [main] workflow_dispatch:
jobs: build-and-deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- uses: pnpm/action-setup@v4- uses: actions/setup-node@v4with:node-version: 22cache: pnpm- run: pnpm install --frozen-lockfile- run: pnpm build- name: Deploy to serveruses: easingthemes/ssh-deploy@v6.0.3with:SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}ARGS: "-rlgoDzvc --delete"SOURCE: "dist/"REMOTE_HOST: ${{ secrets.REMOTE_HOST }}REMOTE_USER: ${{ secrets.REMOTE_USER }}TARGET: "/home/admin/blog"
设置 GitHub Secrets
去仓库 Settings → Secrets and variables → Actions,新建三个:
| Name | Value |
|---|---|
| SSH_PRIVATE_KEY | ~/.ssh/github_actions 私钥内容 |
| REMOTE_HOST | x.x.x.x |
| REMOTE_USER | admin |
第三步:启动静态文件服务
构建好的文件在 /home/admin/blog/,用 Python 起个 HTTP 服务:
cd /home/admin/blog && python3 -m http.server 5544 --bind 0.0.0.0 &
踩坑:80 端口被 nginx 占用
阿里云 ECS 默认装了 nginx 占着 80 端口。本来想用 80 方便直接 IP 访问,结果访问显示 nginx 欢迎页。改成 5544 端口解决。
注意:每次加新端口都要去阿里云安全组放行!
第四步:自定义博客
修改站点配置
编辑 src/config.ts:
export const siteConfig: SiteConfig = {
title: "你的博客名",
subtitle: "副标题",
lang: "zh_CN",
// ...
};
修改头像和个人信息
export const profileConfig: ProfileConfig = {
avatar: "/touxiang.png", // 放 public/ 下避免哈希
name: "你的名字",
bio: "个人简介",
links: [
{ name: "GitHub", icon: "fa6-brands:github", url: "https://github.com/xxx" },
],
};
踩坑:头像加载不出
原来路径写 assets/images/touxiang.png,构建时 Astro 会将其哈希重命名为 _astro/touxiang.XXXX.png,但页面仍引用原路径导致 404。
两种解法:
- 移到
public/目录,路径写/touxiang.png(不会被哈希) - 在
config.ts里用import引入,然后添加env.d.ts类型声明
创建文章
直接在 src/content/posts/ 下建文件夹:
src/content/posts/
├── my-post/
│ ├── index.md
│ └── cover.jpg
index.md 示例:
--- title: 文章标题 published: 2026-05-22 description: 简介 image: ./cover.jpg tags: [标签1, 标签2] category: 分类 draft: false ---
正文内容…
第五步:域名(可选)
买了域名 runrunxka.xyz,去阿里云云解析加两条 A 记录:
| 主机记录 | 记录类型 | 记录值 |
|---|---|---|
| @ | A | x.x.x.x |
| www | A | x.x.x.x |
但国内服务器用域名需要 ICP 备案,否则访问被拦截提示 Non-compliance ICP Filing。暂时用 IP:端口方式访问。
总结
现在每次写完文章或改配置,只需要:
git add . && git commit -m "更新" && git push
GitHub Actions 自动构建并推送到服务器,一分钟内生效。全程不用碰服务器。
整个流程踩了几个坑:
easingthemes/ssh-deploy要用@v6.0.3,@v5不存在- 服务器必须先装 rsync
- 头像路径别用
src/assets/,用public/或 import - 国内服务器域名要备案
- 别用 80 端口,ECS 默认 nginx 占着
希望对同样折腾 Fuwari 的朋友有帮助 🚀
发现错误或想要改进这篇文章?
在 GitHub 上编辑此页