After a few nights of a large number of data access, finally let I to deploy ali cloud success in hexo blog, blog though hexo load under the condition of the static resources more slowly, but still worth learning a blog framework, because before deployment in making hexo, but access is too slow, so the deployment in the cloud. Without further ado, let’s go straight to the tutorial.

Local Hexo installation and initialization

  • First of all, you must build a good blog in the local Windows environment, local access to the line. You can follow the tutorial I wrote earlier. Blog.csdn.net/qq_41684621…

Cloud Server Configuration

  • The centos7.x image on Ali Cloud generally comes with git tools, but the version is relatively low, so it does not affect. You can view its version:



    If you don’t have Git, you can install it using yum
yum install git
Copy the code
  • Create a dedicated user to manage blogs other than root, such as:
useradd git
Copy the code

Modify user permissions:

chmod 740 /etc/sudoers
vim /etc/sudoers
Copy the code

Find the location to add the following sentence

git		ALL=(ALL) 	ALL
Copy the code



You can directly use the forcible save command:wq!

Set git user password

passwd git
Copy the code
  • Configure a remote repository with static files for the local Hexo_blog. Create a private Git repository named hexo_static under /var/repo. Create a bare repository named hexo_static under /var/repo. Then change the directory ownership and user permissions so that git users have the permissions to all newly generated directories and files in the /var/repo directory. Log in as the root user
mkdir /var/repo/
chown -R git:git /var/repo/
chmod -R 755 /var/repo/
Copy the code

Then, run the following command:

cd /var/repo/
git init --bare hexo_static.git
Copy the code

Configure the Nginx managed file directory

  • Create /var/www/hexo directory for Nginx hosting.
mkdir -p /var/www/hexo
Copy the code

As in the previous step, you need to change the ownership and permissions of the directory

chown -R git:git /var/www/hexo
chmod -R 755 /var/www/hexo
Copy the code

Then, modify the Nginx configuration file. For details on nginx installation please visit this blog post I wrote:Blog.csdn.net/qq_41684621…

First, resolve the domain name of your own registered number, such as:



Nginx/WWW /server/nginx/conf/WWW /server/nginx/WWW /server/nginx/WWW /server/nginx/WWW /server/nginx

cd /www/server/nginx/conf
vim nginx.conf
Copy the code

After opening the file, add the following to server:

server {
    listen 80;
    server_name www.yunxdr.top yunxdr.top;
    index index.html index.htm;
    root /var/www/hexo;
	}
Copy the code

You can also add a server and change the serv_name to the resolved secondary domain name. After reinstalling the nginx configuration, you must perform the following operations for the root user:

cd /www/server/nginx/sbin
nginx -s reload
Copy the code
  • Next, create a hook in hexo_static, the bare repository on the cloud server, to transfer the static HTML file to the Web server’s directory, /var/www/hexo, if certain conditions are met

Create a new hook file in the auto-generated hooks directory:

vim /var/repo/hexo_static.git/hooks/post-receive
Copy the code

Add two lines of code to this file that specify the Git working tree (source code) and Git directory (configuration files, etc.).

#! /bin/bash
git --work-tree=/var/www/hexo --git-dir=/var/repo/hexo_static.git checkout -f
Copy the code

Save and exit the file and make it executable.

chmod +x /var/repo/hexo_static.git/hooks/post-receive
Copy the code

At this point, the configuration on the cloud server is complete.

The Hexo configuration in local Windows is complete

  • Modify the Hexo part of the default configuration, this is my local directory file, Hexo blog folder named blog, for example:



    Where _config.yml is the main configuration file of Hexo. Let’s start by changing the URL of the blog.
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://www.yunxdr.top If no domain name is bound, enter the actual IP address of the server.
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
Copy the code

Next, modify default_layout, which is in the Writing section. Change it from POST to Draft, which means that each blog post is a draft by default and must be published before it can be accessed on the blog site.

 
# Writing
new_post_name: :title.md # File name of new posts
default_layout: draft The original value is post
titlecase: false # Transform title into titlecase
Copy the code
  • Create a blog draft and publish it. Here’s a quick demonstration of creating a blog draft with Hexo and publish it. Create your first blog post by executing the following command.
Hexo New My first hexo blog post on Ali Cloud deploymentCopy the code

You should see output similar to the following:



In the local through their familiar editor, edit blog. Here, write the content of this article into the first blog post

Date: 2019-12-12 03:31:48 Tags: -centos-hexo Categories: -hexo Comments:true
---

## Hexo blog was successfully deployed on the Ali Cloud
Copy the code

Then, publish the blog with the following command:

Hexo publish my first hexo post on Ali Cloud deploymentCopy the code

The output looks like the following:





After the blog is pushed to the server, it can be accessed on the website.

  • Continue editing the _config.yml file with Git Deployment, find the Deployment section, and make changes as follows:
deploy:
  type: git repo: [email protected]: / var/repo/hexo_static branch: masterCopy the code

Repo :Centos User@cloud server IP address: raw repository created on the cloud server

Save and exit the file.

After that, you need to install a Hexo package that sends the static content needed for your blog to the Git repository you’ve set up.

npm install hexo-deployer-git --save
Copy the code

After installation, you can test deployment:

hexo generate && hexo deploy
Copy the code

You will be prompted for the git user’s login password. The output after success looks like this:



Later visit:hexo.xdr630.top/