hexo部署在vps上
网上利用GitHub搭建个人的hexo博客的教程很多,而且也比较简单,这里不多介绍。
由于自己有个vps,不想闲置了,于是磕磕绊绊踩了无数的坑,把自己的hexo博客部署在了阿里云学生机上。
大致步骤
- hexo本地
- 创建git用户,并创建一个仓库
- 建立SSH信任关系,并禁用git用户的shell登录权限
- 下载配置nginx
- 测试
hexo本地配置
以下指令,本地新建文件夹(博客本地文件夹),然后右键git bash here后执行
安装git
1 | https://git-scm.com/ |
安装nodejs
1 | https://nodejs.org/en/ |
安装hexo
1 | $ npm install -g hexo-cli |
初始化hexo
1 | $ hexo init//若成功,这个文件夹即为网站根目录,若执行hexo init blog,那么会有个blog文件夹,它为网站根目录 |
以上,hexo就安装好了
hexo init过慢的问题
由于墙的原因,hexo初始化很容易卡死,下面提供解决方案
方案来自:https://blog.nfz.moe/archives/hexokit-intro.html
1
2 //一键脚本,我这边使用无效
curl http://git.oschina.net/neoFelhz/hexokit/raw/master/install.sh | sh
1
2
3
4
5
6
7
8
9
10
11
> ```bash
//一步步执行,执行完后hexokit即网站根目录,主要是更换了npm源
npm config set registry https://registry.npm.taobao.org
npm install hexo-cli -g
git clone https://git.oschina.net/neoFelhz/hexokit.git
rm install.sh
cd hexokit
npm install
npm config set registry https://registry.npmjs.org/
hexo version
新建git用户,创建仓库
以下命令在vps中运行
下载git
1 | git --version //查看git版本,若无,则需要下载git |
创建用户并配置仓库
1 | useradd git //添加git用户 |
建立SSH信任关系,并禁用git用户的shell登录权限
由于每次连接仓库都要输入密码很不方便,需要建立信任关系
配置本地git用户
1 | //配置本地git用户,不然会报有趣的错"你还没告诉我你是谁!"(错误详情写在最后了,因为我是后面碰到的) |
建立ssh信任关系
1 | //以下代码直接在本地新开git窗口执行(不是在网站根目录) |
禁用git用户的shell登录权限
1 | //如果第 5 步能成功,为了安全起见禁用git用户的 shell 登录权限,从而只能用git clone,git push等登录,执行如下命令 |
下载配置nginx
下载安装nginx
1 | cd /usr/local/src |
配置nginx
1 | cd /usr/local/nginx/conf |
运行nginx
1 | nginx -s reload |
此时可能会报错
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file ordirectory)
1 | //使用指定nginx.conf文件的方式重启nginx,然后继续重新执行上面的指令 |
1 | vi nginx.conf |
此时可能会报错
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
1 | ps aux|grep nginx //输入指令 |
root 7110 0.0 0.0 24348 752 ? Ss 22:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 7111 0.0 0.0 26860 1508 ? S 22:32 0:00 nginx: worker process
root 7114 0.0 0.0 112664 968 pts/0 S+ 22:33 0:00 grep —color=auto
1 | kill -9 7110 |
1 | nginx //继续执行 |
修改本地_config.yml站点配置文件
文件在本地在网站根目录中
1 | deploy: |
测试
1 | hexo s //博客本地根目录git执行 |
1 | hexo d -g //生成静态网页并发布 |
若报错1
<strong>ERROR Deployer not found : git
执行1
2
3$ npm install hexo-deployer-git --save
$ hexo g
$ hexo d
若继续报错1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40INFO Deploying: git
INFO Setting up Git deployment...
Initialized empty Git repository in E:/hexo/.deploy_git/.git/
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'dan@dan-PC.(none)')
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/do
cs/troubleshooting.html
Error:
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'XXX@XXX-PC.(none)')
at ChildProcess.<anonymous> (E:\hexo\node_modules\hexo-deployer-git\node_mod
ules\hexo-util\lib\spawn.js:37:17)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at ChildProcess.cp.emit (E:\hexo\node_modules\hexo-deployer-git\node_modules
\hexo-util\node_modules\cross-spawn\node_modules\cross-spawn-async\lib\enoent.js
:37:29)
at maybeClose (internal/child_process.js:827:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
FATAL
是因为本地没配置git用户信息执行1
2
3
4
5$ git config --global user.email "yourname@qq.com"
$ git config --global user.name "yourname"
$ hexo d
其它
- 视频教程来自https://www.bilibili.com/video/av50025574/
- 可能有其他的坑,我不想再踩一次就不一一解决了
- vps安全组问题
- SSH问题
- 手误问题(路径输错,把
/
漏掉了……)
- 主题推荐:强推
next
!虽然烂大街了,但是我还是觉得很好用! - 有空可以学学markdown语法,还是很方便的。
- 详情参阅hexo和next的官方文档,还是挺详细的。