hexo迁移至阿里云
准备:
- 本地hexo环境
- 阿里云机器
- 购买好的域名
操作步骤:
阿里云
-
安装nginx
apt-get install nginx nginx -V
- /usr/sbin/nginx: nginx 主程序
- /etc/nginx: 存放 nginx 相关配置
- /var/log/nginx: 存放 nginx 日志
/etc/nginx 目录下包含 sites-available 和 sites-enabled 目录,sites-enabled 只是 sites-available 的一个软链接。在 sites-available 目录中有个名为 default 的 nginx 配置文件。且 nginx 默认目录为
/var/www/html
-
安装git
apt-get install git git config --global user.name "your name" git config --global user.email "your email"
-
创建git用户
adduser git vim /etc/sudoers 添加 git ALL=(ALL) ALL
-
配置ssh
切换至git用户,
创建
~/.ssh 文件夹和 ~/.ssh/authorized_keys 文件,并赋予相应的权限su git mkdir ~/.ssh vim ~/.ssh/authorized_keys #然后将电脑中执行 cat ~/.ssh/id_rsa.pub | pbcopy ,将公钥复制粘贴到authorized_keys chmod 600 ~/.ssh/authorzied_keys chmod 700 ~/.ssh
-
创建仓库
创建裸仓 hexo.git cd /home/git git init --bare hexo.git 修改 hexo.git 的所有者和组权限: chown -R git:git hexo.git
-
配置钩子
在
hexo.git/hooks
目录下新建一个post-receive
文件,进入cd /home/git/hexo.git/hooks/
,编辑这个文件vim post-receive
#!/bin/bash git --work-tree=/var/www/html/MyZhang0826.github.io --git-dir=/home/git/hexo.git checkout -f
设置这个文件的可执行权限:
chmod +x post-receive
-
域名访问
设置DNS解析,类型A,值写阿里云ip地址即可。
本地
-
配置_config.yml
deploy: - type: git repository: https://github.com/MyZhang0826/MyZhang0826.github.io.git branch: master - type: git repository: git@ip:/home/git/hexo.git branch: master
-
编译上传
hexo -g
Hexo -d
hexo d
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
INFO Copying files from extend dirs...
On branch master
nothing to commit, working tree clean
Everything up-to-date
Branch 'master' set up to track remote branch 'master' from 'https://github.com/MyZhang0826/MyZhang0826.github.io.git'.
INFO Deploy done: git
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
INFO Copying files from extend dirs...
On branch master
nothing to commit, working tree clean
Everything up-to-date
Branch 'master' set up to track remote branch 'master' from 'git@host:/home/git/hexo.git'.
INFO Deploy done: git
最后,欢迎大家访问我的博客:https://keepreal.tech