如何在ECS上部署Hexo博客,实现git提交markdown文档,静态博客自动刷新
ECS购买
阿里云买3年套餐,
ECS配置
创建git用户
1 2 3 4 5 6 7 8 9 10 11
| adduser git chmod 740 /etc/sudoers vim /etc/sudoers
git ALL=(ALL) ALL
chmod 400 /etc/sudoers
sudo passwd git
|
配置git用户免密登陆
1 2 3 4 5 6 7
| su git mkdir ~/.ssh vim ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
|
安装软件
1 2
| yum -y update yum install -y git nginx
|
创建静态文件目录
1
| mkdir -p /home/geosmart.top
|
配置nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| server { listen 80 default_server; listen [::]:80 default_server; server_name geosmart.top; root /home/geosmart.top;
include /etc/nginx/default.d/*.conf;
location / { }
error_page 404 /404.html; location = /40x.html { }
error_page 500 502 503 504 /50x.html; location = /50x.html { } }
|
配置git更新自动同步到静态目录
1 2 3 4 5 6 7 8 9 10 11
| cd /home/git git init --bare blog.git
vim /home/git/blog.git/hooks/post-receive
#!/bin/sh git --work-tree=/home/geosmart.top --git-dir=/home/git/blog.git checkout -f
chmod +x hooks/post-receive
|
配置hexo发布
_config.yml配置
1 2 3 4 5
| deploy: type: git repo: git@47.114.57.4:/home/git/blog.git branch: master message: u
|
发布命令:hexo d -g
问题
hexo deploy权限问题
sudo chmod -R ug+w .;