同步Hexo博客到其他服务器

本文最后更新于:2022年6月1日 下午

服务端设置

安装git和nginx

1
yum install git nginx -y

创建git仓库并使用hooks实现自动部署

1
2
3
4
5
6
7
8
9
10
cd root
git init --bare blogServer.git
vim /root/blogServer.git/hooks/post-receive # 此步骤为创建

post-receive 内容:
#!/bin/sh
git --work-tree=/opt/hexo --git-dir=/root/blogServer.git checkout -f


chmod +x /root/blogServer.git/hooks/post-receive # 增加执行权限

修改nginx路径

1
vim /etc/nginx/nginx.conf
1
/bin/systemctl reload nginx.service   # 重新载入nginx配置文件

服务器增加规则

增加云服务器的安全组规则

本地设置

打开Hexo博客根目录下的_config.yml,将deploy修改

1
2
3
4
5
6
7
8
deploy:
- type: git
repo: https://github.com/Simple2ich4n/Blogs.git
branch: main
token: *****
- type: git
repo: root@ServerIP:/root/blogServer.git
branch: master
  • 注:如果没有择需要增加”-“符号

本地执行上传同步即可

1
2
3
hexo clean
hexo g
hexo d

同步Hexo博客到其他服务器
https://simple2ich4n.top/422/
作者
2ich4n
发布于
2022年3月22日
更新于
2022年6月1日
许可协议