Bricklayer VPS Build Your Own Hexo Blog

Before, in order to access some non-existent websites, I spent 19.99 dollars on a bricklayer to buy a VPS for a year. Recently, I feel that it is a waste to only use the host for FQ. Just recently, there is a need for blogging, so I bought a domain name on NameCheap , and I am going to build my own blog system. After trying systems like WordPress, Ghost, etc., I decided to use Hexo. The following will write down the process of building and the pits encountered in the middle, which is regarded as an archive.

Server settings

After the bricklayer purchases the VPS, you can see the host you purchased through Client Area-Services-My Services in the upper right corner of the website. Through the KiviVM Control Panel, you can perform some simple operations on the host, such as reinstalling the system, replacing the computer room, etc. (For details about the bricklayer, you can learn about the bricklayer Chinese website ).

Before setting up the server, you can reinstall the system first. I chose centOS6 here. Before starting the reinstallation, stop the current host in the Main controls, then select the appropriate linux distribution, and click reload to reinstall. After a few minutes the installation is complete, note the root password and SSH port (usually 29962).

I have installed the pagoda panel on the host here by the way. The installation process is very simple. Use putty or similar tools to connect to the host and follow the official website documentation, which may take some time. After successfully installing the pagoda, log in to the pagoda panel and see if you need to install LNMP or just install Nginx.

ps: After installing the pagoda, the firewall of the pagoda may block some ports. If you find that your ss cannot be used after the installation, please release the ss port in the panel - security.

local settings

My local environment uses Windows 10, so all of the below are Windows 10-based PCs

Install and configure Git

Download the Git version suitable for your system and go to the next step.

After the installation is complete, Git needs to be configured. We use git bash to set our user name and email information:

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

Next, you need to generate a key file, the specific code is as follows:

$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

There are also instructions on key generation and use on github

Install Node.js

Download the Node version suitable for your system, the executable file I chose here. There is nothing to say about the installation process of windows. Just go all the way. Note that there is an option Add to path in the middle, which is to add environment variables. It must be pointed out.

Install Hexo

Open git bash and type in the command line:

$ npm install -g hexo-cli

Waiting for the installation to complete, the local installation work is over at this time, and then the related configuration of Hexo is carried out.

Configure Hexo

Hexo common commands

Create a new blog site and replace the folder with the address you want to create a blog. For example, I use D:\hexo\blog here, and the command is

hexo init /d/hexo/blog

$ hexo init <folder>
$ cd <folder>
$ npm install

After the creation is complete, the file directory is as follows:

.
├── _config.yml 配置文件
├── package.json 应用程序信息,默认安装了EJS, Stylus 和 Markdown renderer
├── scaffolds 模板文件夹
├── source 资源文件位置
|   ├── _drafts
|   └── _posts
└── themes 主题文件夹

If you need to modify the blog title and subtitle, you can open _config.yml to modify the title field and subtitle field. The default language of Hexo is English. If you need to modify it, open _config.yml as well, and modify the language: zh-Hans to set it to Simplified Chinese. For more settings, see the Hexo configuration documentation .

ps: It should be noted here that when modifying the content of the yml file, a space should be added between the colon: and the following value, otherwise an error will be reported

Replace themes

Hexo supports a variety of themes, you can choose the theme you like in the theme list to use, here takes the most popular Next as an example, the operation of replacing the theme is very simple:

$ cd <folder>
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

Then open _config.yml in the root directory of the blog, and modify themes: to themes: next. The next theme supports four different styles. You can modify the scheme in themes/next/_config.yml to switch.

The related settings of the Next topic can be viewed in the Knowing Notes .

Create a new blog post and preview the effect

$ cd <folder>
$ hexo new "your_blog_title"

This command is used to generate a named .md file under source/_posts, the effect is equivalent to creating a new .md file and copying it there.

Next, we will generate a static file for this newly created blog post and deploy it locally to preview the effect. The process is also very simple:

$ cd <folder>
$ hexo generate
$ hexo server --debug

The generate command is used to generate a static web page from the md file, and the server command is used to publish the blog system to the local port 4000. Both commands can be abbreviated as hexo g and hexo s.

ps: Sometimes there is a problem that port 4000 is occupied by other processes. There are two solutions: 1. Release the port occupation of other processes, 2. Use hexo server -p 5000 to modify the port and preview it

After the above command is completed, you can open the browser and enter localhost:4000 to preview the blog post you just generated.

warehouse settings

Now that we can simulate the blog system on this machine, we will deploy it to our VPS. Before that, the code needs to be hosted on a hosting platform such as github. I use github and coding.net here.

github

Create a new project and name it ***.github.io, where *** is your github username, and you can do the next step without thinking.

Upload your SSH Key to github, see GithubHelp for details

Coding.net

Create a new empty warehouse, name it arbitrarily, and then upload your SSH Key to Coding.net, which is simpler than github, skip it.

Hexo setup to deploy to remote repository

Next, we need to set the entire submission of our blog directory to the remote end, open the _config.yml in the root directory, edit the following part of the content, remember to replace *** with your own address:

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: 
    github: git@github.com:***/***.github.io.git,master
    coding: git@git.coding.net:***/***.git,master

After saving, open Git bash and enter the following command:

$ hexo g && hexo d

The former is to generate static pages, and the latter is to submit the code to the remote warehouse, which is the github and coding we just set up.

After the submission is complete, open the github.io you just set up. Have you seen the blog you wrote?

VPS pulls the code and binds the domain name

The centOS used by my vps has the pagoda panel installed, so I used the easiest way to bind the domain name (provided that Nginx has been installed), of course, you can also modify the Nignx configuration file using the command line without using the panel. Effect.

On the pagoda panel, click Website - Add Site - enter the domain name, root directory, and save.

My root directory is saved under /www/wwwroot/blog. At this time, accessing the domain name will prompt that Nginx is set incorrectly, regardless of it.

Open the pagoda panel - file, go to /www/wwwroot/blog, open the command line in this directory, or open the command line with ssh and enter this directory.

input the command:

$ git clone [email protected]:riceeater/riceeater.github.io.git

After the pull is complete, visit your domain name again, and you will find that the blog system has been deployed.

ps: You need to repeat the steps of uploading the SSH key to github on the VPS

Epilogue

At this point, we have basically achieved the goal of building our own blog system on VPS.

Now our creation process is like this, open the command line on the local machine, use hexo new to create a new blog post, use the MarkDown tool to edit the .md file, use the hexo g command to generate a static file, hexo d push the code to the remote warehouse, and then log in to the pagoda, Open the directory where the blog is located and enter the command line git pull. Complete the entire process.

The process is cumbersome. We can add webHook to realize automatic deployment later, that is, after the machine is submitted to github, webHook will notify vps to pull the latest code. Of course, we will talk about this process later (in fact, I haven't understood it yet).

By the way, I recommend a MarkDown tool , Typora , which is simple and beautiful. If the official website cannot be opened, click the backup download address .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325543126&siteId=291194637