使用Github page
配置ssh key
可以参考官网理解每步的意义,这里提供快速命令,前提是你安装了ssh
- 生成公私钥
ssh-keygen -t rsa -b 2048 -f ./github_rsa - 将公钥内容填到自己github中ssh key中
配置
~/.ssh/config没有就创建,添加如下内容1
2
3
4
5Host github.com
HostName github.com
IdentityFile C:\\Users\\yourname\\.ssh\\github_rsa
PreferredAuthentications publickey
User your_account_on_github使用命令测试
ssh -T git@github.com返回ok标识已经ok了
github 新建仓库
- 新建一个仓库,名字必须是
your_account_name.github.io必须是以github.io结尾仓库名,同时记得勾上添加 readme 选项 - 生成仓库后,点击
settings下了到github pages 中 - 第一次配置的话,直接 选择 “choose a theme” 然后随便选择一个风格,这样github会默认在master分支给你创建两个文件
- 接着继续返回的 github pages 页面中,这是可以看到提示
Your site is published at https://your_account_on_github.github.io,这是点击这个url就会看到刚才你随便选得风格
配置hexo
安装依赖
centos 安装
1
2
3curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash
yum install -y nodejs
npm install hexo-cli -g # 缺省安装到 /lib/node_moduleswindow 安装
- 到官网下载nodejs,并安装
- 接着配置在命令行找到npm
npm install hexo-cli -g
搭建hexo
- 找个文件路径 执行如下命令来创建对应博客
hexo init blog这个就在本地创建文件夹 blog hexo g生成静态页面至public目录hexo s运行hexo,按照提示会你在浏览器输入http://127.0.0.1:4000就可以查看你本地的hexo博客
建立hexo跟github pages的关系
- 安装hexo的发布工具
npm install hexo-deployer-git --save其中–save会把安装信息package.json文件中 修改
_config.yml文件中deploy部分如下1
2
3
4deploy:
type: git
repository: your_resposity_url_on_github
branch: master执行命令
hexo deploy发布,就会利用之前配置的ssh key推送到github中- 重新查看之前github pages给的域名,就可以看到属于自己hexo的博客了
问题集合
如果有多个rep,多个仓库发布,如何处理
修改配置_config.yml在repo实现多仓库1
2
3
4
5
6deploy:
type: git
repo:
github: https://github.com/pengloo53/pengloo53.github.io.git
gitcafe: https://gitcafe.com/pengloo53/pengloo53.git
branch: master
修改端口号
修改博客下 _config.yml 中1
2
3
4
5
6
7# Server
server:
port: 4001
log: false
ip: 0.0.0.0
compress: true
header: true
如何跟nginx结合
nginx的配置文件将中地址带blog的转到hexo的服务器上1
2
3
4
5
6
7location ^~ /blog {
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:4001;
}
注意要配合修改博客下 _config.yml 中的 root
无法加载css
f12 打开查看具体请求 css的连接是否 not found, 是的话,是由于配置的blog有可能在服务器已经配置nginx或者启动的路径有问题,需要修改 _config.yml 文件中root的路径
例如如下情况: nginx的配置文件将中地址带blog的转到hexo的服务器上1
2
3
4
5
6
7location ^~ /blog {
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:4001;
}
上述配置是将域名后面以blog开头的转到本地hexo服务
修改blog 下 _config.yml 文件中的 root 如下
1 | root: /blog/ |
重启hexo服务
无法启动 hexo server
执行 hexo server 发现报找不到命令,有一下处理情况:
- 检查是否安装了
hexo server,没有的话就执行命令安装npm install hexo-server --save - 检查是否
_config.yml文件中配置写错了,这个也是很多人在增加插件之后发现写的问题导致的