Github下搭建Hexo博客

GitHub Pages + Hexo搭建个人博客网站

准备工作

  • GitHub账号
  • 安装Git
  • 安装NodeJS
  • 创建仓库,格式必须为<用户名>.github.io

安装Hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
npm install -g hexo-cli

hexo -v

hexo init hexo-blog

cd hexo-blog

npm install

hexo g

hexo server

浏览器访问 http://localhost:4000

更换主题

https://github.com/fluid-dev/hexo-theme-fluid/releases

1
2
3
4
5
6
cd hexo-blog

git clone https://github.com/iissnan/hexo-theme-next themes/next

// 打开 _config.yml 文件 将主题修改为 next
theme: next

发布到GitHub Pages

安装hexo-deployer-git

npm install hexo-deployer-git --save

修改根目录下的 _config.yml,配置 GitHub 相关信息

1
2
3
4
deploy:
type: git
repo: git@github.com:xxx/xxx.github.io.git
branch: master

部署到GitHub

hexo g -d

部署到nginx

  • hexo g 生成静态文件
  • 上传到nginx服务器
  • 配置nginx访问地址
1
2
3
4
5
6
7
8
9
server {
listen 80;
server_name 127.0.0.1;

location / {
root /data/www/blog;
index index.html index.htm;
}
}