Hexo搭建,部署到server
使用Hexo搭建blog,部署到服务器上
Server配置
安装http服务
安装Apache2可参考 Apache服务器安装,配置HTTPS
创建git用户
$ adduser git
修改git用户shell
# vim /etc/passed
定位到
git:x:1000:1000:,,,:/home/git:/bin/bash
将shell修改为/bin/git-shell
创建blog仓库
$ cd /home/git
# sudo -u git mkdir blog.git
(以git用户执行命令,下同)
$ cd blog.git
# sudo -u git git init --bare
clone到Web目录
# rm -rf /var/www/html
# sudo -u git git clone /home/git/blog.git /var/www/html
设置hooks
$ cd /home/git/blog.git/hooks
# sudo -u git cp post-update.sample post-update
$ vim post-update
修改内容为
1 |
|
创建hexo仓库(非必需,hexo项目可以放到本地或GitHub等其他位置)
$ cd /home/git
# sudo -u git mkdir hexo-blog.git
$ cd hexo-blog.git
# sudo -u git git init --bare
至此服务端配置完成。
Local配置
安装npm
$ brew install npm
or $ choco install nodejs
or $ winget install OpenJS.NodeJS
安装hexo
$ npm install hexo-cli -g
创建hexo-blog
$ hexo init hexo-blog
$ cd hexo-blog
$ git init && git add --all && git commit -m "Initial Commit"
$ git remote add origin ssh://git@yourdomain/home/git/hexo-blog.git
$ git push -u origin master
本地预览
$ hexo server
安装NexT主题 (可选)
$ git clone https://github.com/theme-next/hexo-theme-next themes/next
修改主题为next
$ vim _config.yml
1 |
|
初始化配置
$ cp themes/next/_config.yml ./source/_data/next.yml
$ vim source/_data/next.yml
修改override为true
1 |
|
此后使用next.yml来配置NexT主题。
安装hexo-deployer-git
$ npm install hexo-deployer-git --save
$ vim _config.yml
配置仓库
1 | ... |
测试部署
$ hexo clean && hexo deploy
访问https://yourdomain
测试是否部署成功