部署 Blog
部署 Blog
git push -f origin main 覆盖源仓库
由于网络问题可以临时使用vpn
git -c http.proxy=socks5://127.0.0.1:10808 -c https.proxy=socks5://127.0.0.1:10808 push origin main
git status可以检查一下
因为是下载的别人的项目
需要确认
git remote -v
改成自己的
git remote set-url origin https://github.com/timozhuai/727blog.git
查看仓库配置
git config user.name
git config user.email
查看历史提交
git shortlog -sne
git commit -m ""
git push -u origin main -u可以增加追踪关系 下次就直接git push就可以
origin代表仓库地址是个变量
关于子仓库挂载
cd content
# 修改md笔记
git add .
git commit -m "更新笔记"
git push #推送到md_obsidian远程仓库
cd ..
git status
# 你会看到 content 这一项提示 new commits
git add content
git commit -m "更新子模块笔记版本"
git push
或者
子模块会记录内容仓库的某个提交版本;用 `git submodule update --remote` 可拉取其最新提交。
不会自动更新
ubuntu部署
首先apt update
安装apt install -y git nginx curl
安装node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
opencode解决的问题
部署问题排查与修复记录
本文档记录 mozhuai.site 从「公网无法访问 / 404 Not Found」到完全可用的排查过程与修复方案,与
webhook-auto-deploy.md配套阅读。
1. 问题背景
域名
mozhuai.site解析到腾讯云服务器111.229.231.178。访问
http://mozhuai.site/返回 404 Not Found(nginx/1.24.0 默认 404 页)。用户以为 80 端口防火墙未开,实际防火墙正常。
2. 排查结论(逐层定位)
2.1 直接原因:网站从未构建
Nginx 配置正确:
root /var/www/727blog/_site,server_name mozhuai.site。但
/var/www/727blog/_site不存在、node_modules不存在、deploy.log不存在
→ 说明 npm run build 一次都没成功执行过,try_files $uri $uri/ =404 自然返回 404。
2.2 构建失败的真正原因:内容仓库一篇笔记的 front matter 冲突
Eleventy 构建报错:
You attempted to set one of Eleventy's reserved data property names: collections
TypeError: Cannot override reserved Eleventy properties: collections
定位到 content/论文/Welcome-to-Better-Notes-LL6PXVMX.md 的 front matter 含有:
collections: []
collections 是 Eleventy 的保留数据属性(全局集合),不能由页面 front matter 覆盖。
该文件由 Zotero → Obsidian 插件自动生成模板时带入了该字段。
2.3 自动部署链路是断的(webhook 即使触发也会失败)
| 故障点 | 说明 |
| ---- | ---- |
| Git 认证缺失 | 服务器全局 git 配置 url.git@github.com:.insteadof=https://github.com/ 把所有 GitHub 拉取强制改为 SSH,但 ~/.ssh/ 无任何私钥,ssh -T git@github.com 报 Permission denied (publickey);而 md_obsidian 是私有仓库,必须认证 |
| Webhook 从未触发 | deploy.log 不存在证明 deploy.sh 从未执行(脚本第一行就会写日志),最可能是 GitHub 上 Payload URL 配成 https://(当时 443 未启用投递失败)或 Secret 不匹配返回 401 |
| 子模块 detached HEAD | git submodule update 会把 content 子模块切到 detached HEAD,随后 cd content && git pull 报 You are not currently on a branch |
3. 修复方案
3.1 恢复构建(一步到位)
还原
727blog仓库未提交的本地改动(git checkout .)。安装依赖并构建:
```bash
cd /var/www/727blog
npm ci --no-audit --no-fund
npm run build
```
- 修复冲突笔记:删除 front matter 中的
collections: []行。
3.2 Git 认证(账号级 SSH Key,一次配置)
- 在服务器生成密钥:
```bash
ssh-keygen -t ed25519 -C "deploy-727blog" -f /home/ubuntu/.ssh/id_ed25519 -N ""
```
- 把公钥添加到 GitHub 主页 → Settings → SSH and GPG keys(账号级密钥,只需添加一次,
可访问该账号下所有仓库,含私有的 md_obsidian)。
- 验证:
```bash
ssh -T git@github.com # 输出 Hi timozhuai! ... 即成功
```
3.3 修复内容仓库(持久化)
把 collections 修复提交回 md_obsidian 仓库,避免后续自动部署再次被打断:
cd /var/www/727blog/content
git pull origin main
git add "论文/Welcome-to-Better-Notes-LL6PXVMX.md"
git commit -m "fix: 移除 front matter 中与 Eleventy 保留属性冲突的 collections 字段"
git push origin main
3.4 修复部署脚本(detached HEAD 问题)
/opt/727blog-deploy/deploy.sh 的内容更新部分改为在 main 分支上拉取:
# 2. 更新内容子模块(md_obsidian)
git submodule update --init --recursive >> "$LOG_FILE" 2>&1
git -C content checkout main >> "$LOG_FILE" 2>&1
git -C content pull origin main >> "$LOG_FILE" 2>&1
3.5 systemd 服务
配置文件
/etc/systemd/system/garden-webhook.service中WEBHOOK_SECRET=peiyunchao233已正确设置。因单元文件被修改过,执行
sudo systemctl daemon-reload && sudo systemctl restart garden-webhook。
3.6 配置 HTTPS(443)
按 webhook-auto-deploy.md 第 6 节实施:
- 证书位于
/etc/nginx/ssl/mozhuai.site_nginx/:
- mozhuai.site_bundle.crt(证书链)
- mozhuai.site.key(私钥,权限 640,属主 root:www-data,仅 nginx 可读)
- Nginx 站点配置
/etc/nginx/sites-available/727blog:
- 新增 listen 443 ssl; server 块,server_name mozhuai.site www.mozhuai.site
- 80 端口对非 /webhook 路径返回 301 https://$host$request_uri
- 保留 80 端口 /webhook 的代理,避免 GitHub 投递被 301 中断
4. 最终验证结果
| 验证项 | 结果 |
| ---- | ---- |
| http://mozhuai.site/ | 200 |
| http://mozhuai.site/(配置 HTTPS 后) | 301 → https://mozhuai.site/ |
| https://mozhuai.site/ | 200,证书链 Verify return code: 0 (ok) |
| https://www.mozhuai.site/ | 200 |
| /webhook(http / https) | 均正常反代到 127.0.0.1:3000 |
| Webhook 端到端 | 有效签名 POST → 200 Deployed,deploy.log 记录构建完成(77 个页面) |
| SSH 认证 | Hi timozhuai! 成功 |
5. 注意事项
- 本地 Obsidian 需同步修复:
论文/Welcome-to-Better-Notes-LL6PXVMX.md本地版本若仍保留
collections: [],再次编辑推送会复发构建失败,请手动删除该行。
- Webhook URL:GitHub 两个仓库的 Payload URL 可使用
https://mozhuai.site/webhook
(升级后 https 与 http 均可用;https:// 若未启用 443 会投递失败)。
- 密钥权限:私钥文件保持
640(root:www-data),不要改成仅 root 的600,
否则 nginx(以 www-data 运行)无法读取导致启动失败。
6. 当前架构状态
GitHub push (727blog / md_obsidian)
│ HTTPS/HTTP POST /webhook
▼
Nginx (80 保留 /webhook 反代; 443 ssl 全站)
▼
Webhook 服务 (127.0.0.1:3000, systemd garden-webhook)
▼
deploy.sh:git pull + 子模块拉取 + npm ci + npm run build
▼
Nginx 对外服务 /var/www/727blog/_site(Eleventy 构建产物)