这篇文章记录了 hexo 博客从本地安装到部署到服务器的过程。
一、本地安装 hexo
安装
听说 hexo 是一个静态博客系统的时候,就想着没有数据库怎么评论?怎么保存和内容相关的数据?结果一天熟悉下来,发现很适合我。wordpress 越来越好资源,而且对 markdown 支持的不是很好,typora 比较轻量,但可玩性一般。hugo 据说速度很快,但 hexo 能直接用 typora 编辑后发布,我走完 hexo 的整个流程后发现很方便,配置方便,功能丰富,文档和代码都很简洁,完全够用了。没有完美的工具,写博客最主要的是内容。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| npm install -g hexo-cli
hexo init blog
cd blog && npm install
npm i hexo-theme-next
vim _config.yml
language: zh-CN theme: next url: https://<your_website>.com new_post_name: :year-:month-:day-:title.md
hexo server
npm install hexo-renderer-pug hexo-renderer-stylus
|
配置主题
1 2
| cp node_modules/hexo-theme-next/_config.yml _config.next.yml
|
二、发布到 服务器
服务器端设置
服务器可以使用 nginx,也可以使用宝塔面板。宝塔比较方便。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| useradd git && passwd git
mkdir /var/www/hexo chown -R git:git /var/www/hexo
su git && cd git init --bare blog.git
vim blog.git/hooks/post-receive #!/bin/sh git --work-tree=/var/www/hexo --git-dir=/var/repo/blog.git checkout -f
chmod +x blog.git/hooks/post-receive
|
本地配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| cd blog npm install hexo-deployer-git -g
deploy: type: git repo: git@x.x.x.x:blog.git
ssh-copy-id git@x.x.x.x
hexo deploy --generate
|
顺利的话,到这里就完成了。
遇到的问题
1 2 3 4 5 6 7 8 9 10
| 问题:更换默认主题后,执行 `hexo server` 时报错 err: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed 解决:npm install hexo-renderer-pug hexo-renderer-stylus
问题:Authentication refused: bad ownership or modes for file 解决:删除 authorized_keys,重新 ssh-copy-id
问题:服务器的端口不是 22 解决:vim ~/.ssh/config,在这个文件中配置端口 Host x.x.x.x Port yyyy
|