How to build hexo blog on the server

Description link

With Vateral theme developed close to the end, found githubpage problem with a lot of the time before the subject optimized for speed: the first is because of the country's access speed itself is very slow, there was once a time to load the icon of 16kb spent the 26s! ! ? <-! more -> Secondly, when the resources to do accelerated CDN hosted domain name is the need for the record, apparently githubpage also can not do; so decisively to abandon this hexo to build on my Ali cloud server

The whole is more than the hexo on github to build more complicated, and a lot of experience during the pit, also reference a lot of information here detailed summary about the specific steps.

hexo architecture


hexo architecture

First we have to understand how to implement static blog hexo is accessed through the server

By the graph we can know, the whole process is locally through a hexo gstatic file rendering blog, and then through the hexo dgit repository to static files push to the server of our own creation, the server through the git-hooks synchronization root of the site, so that you can access the

Build process


The first step: install node.js and local Hexo initialization
second step: server environment to build, including the installation of Git, Nginx configuration, create user git
third step: to use Git to deploy automated blog publishing

The local environment


Installation node.js

$ brew install node

Initialization Hexo blog

First create your Hexo directory

$ mkdir "your hexo dir name"//创建一个自定义的hexo目录,比如我就在用户根目录创建了一个myhexo文件夹(macOS)
$ cd "your hexo dir name"//进入到刚刚创建的目录

Then install hexo-cli, installation hexo-cli needs root privileges, use sudo to run

sudo npm install -g hexo-cli

Initialize the folder

hexo init

Installation of extensions hexo

npm install

And other plug-ins installed two after the successful implementation, hexo-deployer-git and hexo-server, maybe the role of plug-ins are using Git to automatically deploy, and simple local server.

npm install hexo-deployer-git --save
npm install hero-server --save

And other plug-ins ( * non-mandatory )

npm install hexo-admin --save
npm install hexo-generator-archive --save
npm install hexo-generator-feed --save
npm install hexo-generator-search --save
npm install hexo-generator-tag --save
npm install hexo-generator-sitemap --save

Here hexo local structures has been basically over, come and start a new article in the local bar ~

Build your own first article

Use hexo new <article name> to create a new article, the command to be placed into a .md file sources / _posts folder. ( * In hexo directory execute command )

hexo new "hello Hexo"

Sources in the hexo directory After executing the command / _posts folder generated hello just created
Hexo.md of markdown file, then you can you can create your own blog through local or online markdown editor of the ~

After editing is completed, use hexo g render .md files into static files, and then start hexo-server

hexo g
hexo server

Open http: // localhost: 4000 If you see the initial page hexo prove successful installation.

Ssh public key generation

$ cd ~/.ssh
$ ssh-keygen

It first asks you to confirm the location to save the public key (.ssh / id_rsa), then it will make you repeat a password twice, if you do not want to enter a password when using the public key can be left blank; specific production methods can be found here

The public will be copied to the server's certificate, and then add the public key can be prevented to enter your password each time push.

At this point, the local built environment has been basically completed.

Server environment to build


Install nginx

Because we do is take nginx Web server, so we need to install nginx deployed, if not installed, it recommended LNMP a key installation package

We can be created specifically for the hexo a deployment directory, for example, I created the / home / www / hexo folder, and the configuration file nginx.conf nginx in the deployment directory to / home / www / hexo, usually in the configuration file / usr / local / nginx / conf Lane; likewise possible to use the default directory, the default directory is nginx / var / www / html, if LNMP using a key installation package, the default directory is deployed / home / wwwroot / default

Installation node.js

$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
$ apt-get install -y nodejs

If you encounter problems you can refer Node.js deployed to Ali cloud server inside a more detailed steps on the node.js

Install git

$ apt-get install git

To create a git user

$ sudo adduser git

Although now only our own warehouses in use, create a new user git seems not necessary, but for safety reasons, it is recommended to use a separate user to specifically run git
git Service

Add Certificate Login

The newly created locally or already have a public key, which is ~ / .ssh / id_rsa.pub file to /home/git/.ssh/authorized_keys add the contents of a file server, as noted above, add the public key after each push can be prevented to enter your password. (* Can be performed directly cat ~/.ssh/id_rsa.pub | pbcopycopy)

Initialization Git repository

git repository can put a custom location, I put it under /var/repo/blog.git directory

$ sudo mkdir /var/repo
$ cd /var/repo
$ sudo git init --bare blog.git

Use --bare parameters, Git creates a bare warehouse, bare warehouse area did not work, we do not operate on a bare warehouse, it only exists to share.

Configure git hooks

We are here to use the post-receive the hook, the hook will be run after the end of operation throughout git, hooks on
the details of the contents can be found here .

Create a new file in the post-receive blog.git / hooks directory

$ cd /var/repo/blog.git/hooks

Edit this file

$ vim post-receive

Written following the post-receive file

#!/bin/sh
git --work-tree=/home/www/hexo --git-dir=/var/repo/blog.git checkout -f

Note, / home / www / hexo to deploy into your own catalog, as stated above, I am of the configuration directory is / home / www / hexo. /var/repo/blog.git is the location git repository. The above sentence git command after we finish each push, the deployment directory update to the latest generation of state blog. This will be done to achieve the purpose of the automatic deployment.

Set the executable file permissions

chmod +x post-receive

Owner change blog.git git directory for users

$ sudo chown -R git:git blog.git

Disable git user's login shell rights

For security reasons, we can not let the git user login shell. You can edit the / etc / passwd to achieve

vim /etc/passwd

will

git:x:1001:1001:,,,:/home/git:/bin/bash

Change

git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

In this way the user can ssh git normal use git, but can not log sehll.

At this point, set up the server environment has been basically completed.

_Config.yml local configuration file, complete automated deployment


Now configure deploy hexo of.

Modify _config.yml under hexo directory to find deploy, amended as follows:

deploy:
type: git
repo: [email protected]:/var/repo/blog.git
branch: master

repo address as your own address and git repository directory

At this point, we have all been configured to automatically deploy hexo good

start using

New article:

$ hexo new "post name"

Generation & deployment:

$ hexo clean && hexo g && hexo d

reference

Hexo blog set up on the VPS, use Git to deploy
Ali cloud VPS to build their own in Hexo blog
use Git Hook VPS automatically deploy Hexo to personal
use git hooks were hexo blog automated deployment

Finally, I welcome the use recently developed as the theme Vateral hexo View demo if you like a star dalao to support what ~

This article is reproduced in: ape 2048➩ https://www.mk2048.com/blog/blog.php?id=hac1k2ibhaa

Guess you like

Origin www.cnblogs.com/homehtml/p/12499632.html
Recommended