GitHub Pages is too slow, and even with a VPN, it sometimes gets stuck.

Setting Up a Git Server

First, connect to the server using Xshell and switch to the root user. Then navigate back to the root directory.

  1. Install openssh

    1sudo apt-get install openssh-server # Ubuntu
    2sudo yum install openssh-server # Centos
    
  2. After installation, check if the ssh service is running

    1ps -e|grep ssh
    
  3. Create a user named git to manage the Hexo project

    1adduser git
    
  4. Add write permissions for the git user

    1chmod 740 /etc/sudoers
    2vim /etc/sudoers
    

    Find the User privilege specification section and add the following line:

    1git    ALL=(ALL:ALL) ALL
    
  5. Press ESC to exit edit mode, then type :wq to save and exit

  6. Revoke write permissions

    1chmod 400 /etc/sudoers
    
  7. Switch to the git user, create the ~/.ssh folder and the ~/.ssh/authorized_keys file, and assign the appropriate permissions

    1su git
    2mkdir ~/.ssh
    3vim ~/.ssh/authorized_keys
    

    Press i to enter edit mode, copy the public key from the previously generated id_rsa.pub file into authorized_keys, then press ESC to exit edit mode and type :wq to save and exit.

  8. Assign permissions

    1chmod 600 /home/git/.ssh/authorized_keys
    2chmod 700 /home/git/.ssh
    
  9. On your local computer, right-click and select Git Bash Here, then enter the following command, replacing SERVER with your cloud server’s IP. If you can log in without a password, it means it’s successful.

    1ssh -v git@SERVER
    
  10. Install git (skip if already installed)

    1# Install Git
    2sudo yum -y install git
    3# Check version
    4git version
    
  11. Create a repo directory in the var directory as the Git repository directory, and assign permissions. First, switch to the root account, then enter:

    1mkdir /var/repo
    2chown -R git:git /var/repo
    3chmod -R 755 /var/repo
    

    Create a hexo directory as the website root directory and assign permissions

    1mkdir /var/hexo
    2chown -R git:git /var/hexo
    3chmod -R 755 /var/hexo
    

    Create an empty git repository

    1cd /var/repo
    2git init --bare hexo.git
    

    In /var/repo/hexo.git, there is an automatically generated hooks folder. We need to create a new hook file post-receive for automatic deployment

    1vim /var/repo/hexo.git/hooks/post-receive
    

    Enter edit mode and input the following content:

    1#!/bin/bash
    2git --work-tree=/var/hexo --git-dir=/var/repo/hexo.git checkout -f
    

    After writing, add executable permissions

    1chown -R git:git /var/repo/hexo.git/hooks/post-receive
    2chmod +x /var/repo/hexo.git/hooks/post-receive
    

Configuring Nginx to Host the File Directory

  1. Install Nginx

    1sudo yum install nginx -y
    

    After successful installation, enter the server’s IP address in the browser to access the default Nginx site

  2. Configure Nginx

    1nginx -t
    

    Edit the nginx.conf file

    1vim /etc/nginx/nginx.conf
    

    Press i to enter edit mode, paste the content, then press Esc to exit edit mode and type :wq to save and exit.

  3. Start nginx

    1systemctl start nginx.service
    

    Restart nginx

    1systemctl restart nginx.service
    

Modifying Hexo Configuration

In the _config.yml configuration file, find deploy and modify it as follows:

1deploy:
2  type: git
3  repo: [email protected]:/var/repo/hexo.git #repo改为repo: [email protected]:/var/repo/hexo.git
4  branch: master

Triple deployment

1hexo cl & hexo g & hexo d