Hexo blog deployed to Alibaba Cloud server

Hexo blog deployed to Alibaba Cloud server

Mainly refer to this blog ! I did it myself and recorded it~

1. Get a server

1.1 Purchase server and domain name

Today on a whim, I bought a server to play with

1.2 Purchase a domain name

Just buy it~

1.3 Configure Security Group Rules

Alibaba Cloud does not authorize port 80 access by default, so we configure it manually (otherwise the server cannot be accessed)

0J3DNq.png

2. Configure the server environment

2.1 Install nginx server

We first need to install the nginx server (default path /etc/nginx/)

yum install -y nginx

Then start the server:

systemctl start nginx
systemctl enable nginx

Then we can access our server through the public IP

0J8MxU.png

2.2 Configure server routing

Because we want our address to point to our blog instead of nginx's index.html, we need to modify the nginx configuration file to be located etc/nginx/nginx.conf(of course, there may be some differences due to the different locations of nginx versions).

We are etc/nginx/creating a new folder vhost, and then creating a blog.confconfiguration file.

cd /etc/nginx
mkdir vhost
cd vhost
vim blog.conf

Enter the following content and save

server{
	listen    80;
	root /home/www/website;这里填博客目录存放的地址
	server_name 这里填域名如(www.baidu.com) 如果暂时没有域名就填阿里云的公网ip,以后有了再改回来;
	location /{
	}
}

Then we go to edit the nginx.conf file under etc/nginx/

0JtbBF.png

3. Install Git and Node.js

3.1 Install Node.js

Enter the following command to install Node.js

curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs

Then it's installed

0YKch8.png

3.2 Install git and configure warehouse

Install git

yum install git

Configure git user

adduser git

Modify user permissions:

chmod 740 /etc/sudoers
vim /etc/sudoers

Add in the position below

git ALL=(ALL) ALL

0YMQC8.png

After saving and exiting, change the sudoers file permissions back to the original

chmod 400 /etc/sudoers

Set the password of the git user

sudo passwd git

Switch to the git user, and create a .ssh folder in the ~ directory

su git
cd ~
mkdir .ssh
cd .ssh

Generate public key key file

ssh-keygen

There will be two files in the directory at this time, namely

id_rsa 和 id_rsa.pub

Where id_rsa.pub is the public key file, we copy

cp id_rsa.pub authorized_keys

There will be an authorized_keys file in the directory, which is exactly the same as id_rsa.pub.
Finally we modify its permissions

chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh

Then on your own computer, use ssh to connect to the server:

ssh -v git@自己的公网ip

0YhEtA.png

Then create a git repository

cd ~
git init --bare blog.git
vi ~/blog.git/hooks/post-receive

After creation, enter the following:

git --work-tree=/home/www/website --git-dir=/home/git/blog.git checkout -f

Save and exit and grant permissions

chmod +x ~/blog.git/hooks/post-receive

4. Hexo installation

Then the local Hexo is installed, which is very simple, and there are many online tutorials (mainly I am lazy, I don’t want to demonstrate it again after I have installed it~)

After installation, you only need to configure it _config.yml.

deploy:
type: git
repo: git@这里改为服务器公网IP:/home/git/blog.git       
branch: master                           
message:                                  

Then you can deploy hexo to the server~

Then re-run the nginx server

nginx -s reload

You can access it by visiting your public network ip or domain name~

Guess you like

Origin blog.csdn.net/weixin_44338712/article/details/108930607