preamble

If you feel that the Blog hosting service is not enough to satisfy your own folding, you can migrate the resources to your own cloud servers

goal

  • Server-side deployment of hexo blog site environment
  • Client publishes articles to push to server

Preparing the environment

Essential Software for Servers

  • Git
  • Nginx

Client Essentials

  • Git
  • Node.js
  • hexo

Server-side configuration (using Centos as an example)

Adding Epel sources to facilitate yum installation of Nginx

Terminal window
wget https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -ivh epel-release-7-11.noarch.rpm
yum clean all
yum makecache

Install Git and Nginx

Terminal window
yum install git nginx -y

Creating Nginx Users and Groups

Terminal window
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx

Creating the Nginx hexo site files directory

Terminal window
mkdir -pv /webdata/www/hexo
chown -R nginx:nginx /webdata/www/hexo

Configuring Nginx Configuration file path

Terminal window
vim /etc/nginx/nginx.conf

Required modifications

Terminal window
.....
server {
listen 80 default_server;
server_name www.example.com;
root /webdata/www/hexo;
index index.html index.htm;
}
.....

Run service nginx configtest to check if the syntax of nginx.conf is correct, display success and then restart service nginx restart

Git Deployment Create a file directory for private Git repository building

Terminal window
mkdir -pv /data/repository

Git Initializes Bare Libraries

Terminal window
cd /data/repository
git init --bare hexo.git

Creating Git hooks (hooks)

Terminal window
vim /data/repository/hexo.git/hooks/post-receive

Specify the Nginx site directory and Git repository address

#!/bin/bash
git --work-tree=/webdata/www/hexo --git-dir=/data/repository/hexo.git checkout -f

Save to exit and add execute permissions

Terminal window
chmod +x /data/repository/hexo.git/hooks/post-receive

Client Configuration

This article to the local virtual machine Centos as an example, other platforms corresponding to the search to know how to install. Install Git and Nodejs

Terminal window
yum install git nodejs -y

Install hexo

Terminal window
npm install -g hexo-cli

hexo initialization and installation

Terminal window
mkdir -pv <folder> (/data/www/hexo)
hexo init <folder>
cd <folder>
npm install

For detailed configuration of hexo, please refer to hexo documentation.

Configure the local client-server connection Open the site configuration file

Terminal window
vim /data/www/hexo/_config.yml

Setting the Deployment field

Terminal window
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: root@domain && IP:/data/repository/hexo.git # SSH default port 22
#repo: ssh://root@domain && IP:prot/data/repository/hexo.git # SSH non-default port 22
branch: master

If it is too much trouble to enter the password every time you publish, you can configure client-side and server-side RSA authentication, if you don’t know you can find it through a search engine.

Configuring Git Mailboxes and Users Git requires mailbox and user configuration for initial connection

Terminal window
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

Deploying hexo

Deploying locally generated static files to a server clear the cache

Terminal window
hexo clean

Generate static pages

Terminal window
hexo generate

Start server

Terminal window
hexo server # Not necessary for debugging web pages

Deploying local hexo catalog files to the server But before you do that you need to install the hexo-deployer-git plugin

Terminal window
npm install hexo-deployer-git --save

Then execute the deployment

Terminal window
hexo deploy

concluding remarks

It seems to write a big push, in fact, there are not many places to configure, Blog deployment instead of simple.