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.
Install
openssh
1sudo apt-get install openssh-server # Ubuntu 2sudo yum install openssh-server # Centos
After installation, check if the
ssh
service is running1ps -e|grep ssh
Create a user named
git
to manage theHexo
project1adduser git
Add write permissions for the
git
user1chmod 740 /etc/sudoers 2vim /etc/sudoers
Find the
User privilege specification
section and add the following line:1git ALL=(ALL:ALL) ALL
Press
ESC
to exit edit mode, then type:wq
to save and exitRevoke write permissions
1chmod 400 /etc/sudoers
Switch to the
git
user, create the~/.ssh
folder and the~/.ssh/authorized_keys
file, and assign the appropriate permissions1su git 2mkdir ~/.ssh 3vim ~/.ssh/authorized_keys
Press
i
to enter edit mode, copy the public key from the previously generatedid_rsa.pub
file intoauthorized_keys
, then pressESC
to exit edit mode and type:wq
to save and exit.Assign permissions
1chmod 600 /home/git/.ssh/authorized_keys 2chmod 700 /home/git/.ssh
On your local computer, right-click and select
Git Bash Here
, then enter the following command, replacingSERVER
with your cloud server’s IP. If you can log in without a password, it means it’s successful.1ssh -v git@SERVER
Install
git
(skip if already installed)1# Install Git 2sudo yum -y install git 3# Check version 4git version
Create a
repo
directory in thevar
directory as theGit
repository directory, and assign permissions. First, switch to theroot
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 permissions1mkdir /var/hexo 2chown -R git:git /var/hexo 3chmod -R 755 /var/hexo
Create an empty
git
repository1cd /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 filepost-receive
for automatic deployment1vim /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
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
Configure
Nginx
1nginx -t
Edit the
nginx.conf
file1vim /etc/nginx/nginx.conf
Press
i
to enter edit mode, paste the content, then pressEsc
to exit edit mode and type:wq
to save and exit.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