目录

Hexo远程部署Vultr

1. 本地操作

  • Hexo安装完成

  • Git安装完成

  • Git配置(Git Bash)

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

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

2. Vultr配置

  • 新建用户

    1
    
    useradd git
    
  • 创建authorized_keys

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    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

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

    1
    2
    3
    4
    5
    
    su git
    cd ~
    mkdir hexo.git
    cd hexo.git
    git init --bare
    
  • 创建网站目录

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

    1
    2
    3
    
    su git
    cd ~/hexo.git/hooks
    vi post-receive # 内容如下
    
    1
    2
    3
    4
    5
    6
    7
    8
    
    #!/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}
    
  • 赋予执行权限

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

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

    1
    
    vi /etc/nginx/conf.d/hexo.conf #内容如下
    
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
    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

    1
    
    systemctl restart nginx
    

3. Hexo配置

  • _config.yml文件配置如下:

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

完事……