Hexo远程部署Vultr

Hexo远程部署Vultr

September 27, 2017

1. 本地操作

  • Hexo安装完成

  • Git安装完成

  • Git配置(Git Bash)

    git config --global user.name "你的用户名"
    git config --global user.email "你的电子邮箱"
  • Git SSH Keys(Git Bash)

    cd ~
    mkdir .ssh
    cd .ssh
    ssh-keygen -t rsa
  • Hexo安装hexo-deployer-git插件

2. Vultr配置

  • 新建用户

    useradd git
  • 创建authorized_keys

    su git
    cd ~
    mkdir .ssh
    cd .ssh
    vi authorized_keys
    # 复制本机  ~/.ssh/id_rsa.pub  内容到此
    su #切换root
    chmod 600 /home/git/.ssh/authorized_keys
    chmod 700 /home/git/.ssh
  • 安装Git和Nginx

    su #切换root
    yum -y update
    yum install -y nginx git-core
  • 创建Git仓库目录

    su git
    cd ~
    mkdir hexo.git
    cd hexo.git
    git init --bare
  • 创建网站目录

    su # 切换root
    mkdir -p /home/wwwroot/hexo
    chown git:git -R /home/wwwroot/hexo # 变更所有人
  • 配置Git Hook

    su git
    cd ~/hexo.git/hooks
    vi post-receive # 内容如下
    #!/bin/bash
    GIT_REPO=/home/git/hexo.git # git 仓库
    TMP_GIT_CLONE=/tmp/hexo
    PUBLIC_WWW=/home/wwwroot/hexo #网站目录
    rm -rf ${TMP_GIT_CLONE}
    git clone $GIT_REPO $TMP_GIT_CLONE
    rm -rf ${PUBLIC_WWW}/*
    cp -rf ${TMP_GIT_CLONE}/* ${PUBLIC_WWW}
  • 赋予执行权限

    chmod +x post-receive
  • 禁止Git用户登陆控制台

    su //切换root
    vi /etc/passwd
    #找到 git:x:1000:1000::/home/git:/bin/bash 把 /bin.bash 改成 /usr/bin/git-shell
  • 配置Nginx

    vi /etc/nginx/conf.d/hexo.conf #内容如下
    server {
      listen         80 ;
      root /home/wwwroot/hexo;
      server_name XX.XX.com; # 域名
      access_log  /var/log/nginx/hexo_access.log;
      error_log   /var/log/nginx/hexo_error.log;
      location ~* ^.+\.(ico|gif|jpg|jpeg|png)$ {
        root /home/wwwroot/hexo;
        access_log   off;
        expires      1d;
      }
      location ~* ^.+\.(css|js|txt|xml|swf|wav)$ {
        root /home/wwwroot/hexo;
        access_log   off;
        expires      10m;
      }
      location / {
        root /home/wwwroot/hexo;
        if (-f $request_filename) {
        rewrite ^/(.*)$  /$1 break;
        }
      }
    }
  • 重启Nginx

    systemctl restart nginx

3. Hexo配置

  • _config.yml文件配置如下:

    deploy:
    - type: git 
      repo: git@域名:/home/git/hexo.git

完事……

最后更新于