使用Hexo搭建个站
本文将记录搭建本站的过程,以及踩过的那些坑。
搭建环境:
- 域名 - 阿里云
- Hexo 5.4.0
- Git
准备工作
安装hexo
$ npm install -g hexo-cli
初始化
hexo init blog
创建GitHub仓库
- 登录GitHub
- New repository
- 设置仓库名为 用户名.github.io
本地测试
1 | hexo n new_blog #新建博文 |
浏览器地址:localhost:4000
生成SSH密钥文件
1 | git config --global user.name "Git用户名" |
配置GitHub密钥
这里卡了很久,原因是 GitHub 从2021年8月13日开始不接受用户密码的方式进行 Git 操作验证,于是改为 SSH 连接。
- GitHub - Setting - SSH and GPG keys
- New SSH key
- 复制上一步生成的公钥 id_rsa.pub 的内容到 Key 中
- Add SSH key
- 测试是否配置成功
ssh -T git@github\.com
Git推送
修改 blog 文件夹下的配置文件 _config.yml
1
2
3
4deploy:
type: git
repo: 粘贴GitHub仓库的SSH Clone地址
branch: 当前分支名(可能为main或master)tips: 修改branch名称
- 仓库Setting - Branches
保存配置文件
安装 Git 部署插件
npm install hexo-deployer-git --save
清除缓存
hexo cl
生成
hexo g
部署
hexo d
浏览器地址:https://用户名.github.io
hexo d 出错的解决办法
可根据报错信息自行尝试。
取消代理
git config --global --unset http.proxy
修改 hosts 文件
92.30.255.113 github.com
网络连接问题
修改缓存大小
git config --global http.postBuffer 524288000
配置 git 的最低速度和最低速度时间
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999
绑定域名
阿里云 - 控制台 - 域名 - 域名列表 - 解析 - 添加记录
记录类型:A
主机记录:@
解析线路:默认
记录值:192.30.252.154
记录类型:A
主机记录:@
解析线路:默认
记录值:192.30.252.153
记录类型:CNAME
主机记录:www
解析线路:默认
记录值:填写 用户名.github.io
GitHub 仓库 - Setting - Pages - Custom domain 填写阿里云域名 - Save
本地 blog 文件夹 - source - 新建文本文件 - 内容填写阿里云域名 - 命名为 CNAME 格式为所有文件 - 保存
hexo cl #清除缓存 hexo g #生成 hexo d #部署
浏览器输入域名测试访问