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
wget https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpmrpm -ivh epel-release-7-11.noarch.rpmyum clean allyum makecacheInstall Git and Nginx
yum install git nginx -yCreating Nginx Users and Groups
groupadd nginxuseradd -g nginx -s /sbin/nologin nginxCreating the Nginx hexo site files directory
mkdir -pv /webdata/www/hexochown -R nginx:nginx /webdata/www/hexoConfiguring Nginx Configuration file path
vim /etc/nginx/nginx.confRequired modifications
.....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
mkdir -pv /data/repositoryGit Initializes Bare Libraries
cd /data/repositorygit init --bare hexo.gitCreating Git hooks (hooks)
vim /data/repository/hexo.git/hooks/post-receiveSpecify the Nginx site directory and Git repository address
#!/bin/bashgit --work-tree=/webdata/www/hexo --git-dir=/data/repository/hexo.git checkout -fSave to exit and add execute permissions
chmod +x /data/repository/hexo.git/hooks/post-receiveClient 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
yum install git nodejs -yInstall hexo
npm install -g hexo-clihexo initialization and installation
mkdir -pv <folder> (/data/www/hexo)hexo init <folder>cd <folder>npm installFor detailed configuration of hexo, please refer to hexo documentation.
Configure the local client-server connection Open the site configuration file
vim /data/www/hexo/_config.ymlSetting the Deployment field
## Docs: https://hexo.io/docs/deployment.htmldeploy: 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: masterIf 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
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
hexo cleanGenerate static pages
hexo generateStart server
hexo server # Not necessary for debugging web pagesDeploying local hexo catalog files to the server
But before you do that you need to install the hexo-deployer-git plugin
npm install hexo-deployer-git --saveThen execute the deployment
hexo deployconcluding remarks
It seems to write a big push, in fact, there are not many places to configure, Blog deployment instead of simple.