准备

核心是在原本Github Page推送的基础上,增加一条推送向云服务器的deploy,适用于增加更多部署。

GitHub Page

本地已经配安装置好git、hexo,见‘此处’

服务器

已搭建好LNMP框架下的网页目录,见此处

搭建

本地git

1
ssh-keygen -t rsa

密钥默认位置:C盘用户文件夹下.ssh中,如已有则不需要生成。

服务器git

安装git

1
apt-get install git

创建git用户及ssh设置

1
2
3
4
sudo adduser git
su git
cd ~
mkdir .ssh && chmod 700 .ssh
1
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

authorized_keys中写入本地生成的公钥

git仓库

home中的git用户文件夹作为仓库目录

1
git init --bare hexoBlog.git

/home/git/hexoBlog.git 下,有一个自动生成的 hooks 文件夹。我们需要在里边新建一个新的钩子文件 post-receive记得赋予执行权限。

1
vim /home/git/hexoBlog.git/hooks/post-receive

在该文件中添加两行代码

1
2
3
#!/bin/bash
git --work-tree=/var/www --git-dir=/home/git/hexoBlog.git checkout -f
#--work-tree是网页目录,--git-dir是git仓库目录

Nginx托管目录

假设在/var/www,需要更改目录权限

1
chown -R $USER:$USER /var/www

Hexo

本地的 Hexo 博客所在文件,修改站点配置文件,增加一条推送向云服务器的deploy

1
2
3
4
5
deploy:
repo:
#增加一行
hexo: git@ip:/home/git/hexoBlog.git,master
#这里的@前的git是云服务器的git用户,也可以是root什么的,与云端对应

参考HEXO部署到云服务器详细指南Hexo教程:Hexo 博客部署到腾讯云教程