最近,在阿里云淘了一台2核2G1Mbps的云服务器,有效期一年,就想着折腾一下,先在服务器上建立一个自己的博客,仅对自己开放(国内服务器,懒得备案了)。然后我wordpress和typecho都试了一下,发现都要自己重头开始配置,嫌麻烦,太费时间了,索性就用hexo静态博客了。

直接在服务器上搭建

  1. 前提。

    已经搭建好git服务器

  2. 创建仓库。

    1
    2
    cd /home/git/gitrepo
    git init --bare blog.git
  3. 配置git-hooks

    1
    2
    cd blog.git/hooks
    vim post-receive

    post-receive文件中添加下述内容。

    1
    2
    #!/bin/bash
    git --work-tree=/www/wwwroot/myblog --git-dir=/home/git/gitrepo/blog.git checkout -f

    上述代码意思是把提交到git仓库的文件同步到博客目录中,我的博客目录为:/www/wwwroot/myblog

    为其添加权限并改变博客文件所有者:

    1
    2
    chmod +x /home/git/gitrepo/blog.git/hooks/post-receive
    chown -R git:git /home/git/gitrepo/blog.git
  4. 创建博客目录。

    1
    2
    3
    mkdir /www/wwwroot/myblog
    chown -R git:git /www/wwwroot/myblog
    chmod -R 755 /www/wwwroot/myblog
  5. 配置本地站点文件。

    打开_config.yml文件。

    1
    2
    3
    4
    5
    6
    7
    deploy:
    - type: git
    repo: git@github.com:jianerssr/jianerssr.github.io.git
    branch: main
    - type: git #自己服务器网站
    repo: git@myip:/home/git/gitrepo/blog.git
    branch: master

    over,尽情地hexo && clean && hexo g && hexo d吧。