Article Directory
I recently purchased Alibaba Cloud's cloud server and domain name, and set up a blog by myself. Here I will share the record of the construction process.
This is the blog I set up . Welcome everyone to visit! ! !
1. Local computer
1.1 Install node.js
The browser enters the official website of NodeJS and installs the LTS (Long Term Support) version, which is stable.
Press win+R
and hold , enter cmd
, enter the cmd command line tool, enter to node -v
view the node version,
If the version information appears, the node installation is successful.
1.2 Install hexo
Enter in the cmd command line to npm install hexo-cli -g
install hexo. After completion, enter the hexo -v
view version information to confirm that the installation is successful.
-
Initialize the root directory
Create a folder
Hexo-Blog
, enter the directory in the cmd command line, and enter thehexo init
initial root directory. -
Local view
Input
hexo g&&hexo s
(generate a static file and start the local server)Follow the prompts and open it in the browser
http://localhost:4000
to see the initial blog page. -
beautify
Change the style of your blog, beautify, add and delete functions, publish articles, etc., so I won’t introduce it.
Second, buy a domain name
-
Buy a domain name
I purchased
lzxjack.top
this domain name on Alibaba Cloud at a discount for student certification . -
Domain name registration
The domain name is bound to a domestic server and must be filed, otherwise it will not be accessible.
It took less than 10 days from the submission of the filing information to the approval of the administrative bureau.
-
DNS
Domain name resolution is a service that points the domain name to the website space IP so that people can easily access the website through the registered domain name. An IP address is a digital address that identifies a site on the network. In order to facilitate memory, a domain name is used to replace the IP address to identify the site address.
- In the host record, the
www
representative domain name is added beforewww.
, for examplewww.lzxjack.top
,@
it meanslzxjack.top
that both addresses can access the server - The record type
A
refers to pointing the domain name to anIPV4
address - The recorded value is the public IP of the server
- In the host record, the
Three, server side
3.1 Purchase server
In order to allow other users to access their own blogs on their clients, they need to be deployed on the server, and other users can access the resources on the server by accessing the server’s public IP. If the domain name is bound, you can also access it through the domain name.
Purchased through the Alibaba Cloud Developer Growth Plan轻量应用服务器
. In the choice of the system, as a server system, CentOS is stable and powerful, so the system mirror chooses the CentOS 7.3 version of the Linux system.
3.2 Configure Port
Click on the cloud server management page 防火墙
, and then click 添加规则
.
To use the HTTP protocol to access the server, you need to monitor port 80 on the server side, because port 80 is the default port number of the server. The Alibaba Cloud server closes port 80 by default, so we need to manually open port 80 for listening. In addition, when configuring Git on the server side, you need to use the SSH protocol to connect locally to the server, and the server needs to monitor port 22, and you need to manually open it.
3.3 Setting up the server environment
This step needs to be completed on the cloud server. The specific method can be remote connection or Xshell client connection.
- Install nginx
- Switch to root account
sudo su root
- Need to use nginx as a web server, so we must first install nginx. You can use the yum command to install directly.
yum install -y nginx
- After the installation is complete, start the nginx server
systemctl start nginx
systemctl enable nginx
-
Create blog root directory
Put the blog page files in the
/home/www/website/
path, you need to create these files first.
cd /home
mkdir www
cd www
mkdir website
View the created file:
-
Configure nginx routing
After the root directory of the blog is established, you need to point the nginx server to this root directory address to access the blog page, so you need to modify the nginx configuration file.
Alibaba Cloud's default library download is based on fedora's nginx. After consulting the data, it is found that the default configuration file is located
etc/nginx/
undernginx.conf
.View the default configuration file of nginx:
cd ~
cd /etc/nginx
ls
The file nginx.conf
is the default configuration file.
But instead of directly modifying the nginx configuration file, you create a new folder and write your configuration in the newly created folder . To reuse include
, just nginx.conf
import the folder in the configuration file . In this way, if there is a new requirement, you only need to add the configuration file of the new requirement in the folder, and the configuration file will not be modified again nginx.conf
, which improves efficiency.
Change /etc/nginx/
directory and create a folder in this directory vhost
:
cd /etc/nginx
mkdir vhost
cd vhost
Enter the vim blog.conf
new blog.conf
file and edit the content:
server{
listen 80;
root /home/www/website;
server_name lzxjack.top;
location /{
}
}
Among them, it listen
represents listening on port 80. root
It is the root directory of the blog and the address where the page is stored. server_name
Is the server name, fill in the domain name lzxjack.top
, and bind the domain name to the root directory of the blog page .
In order to http://www.lzxjack.top/
also be able to access the blog page, create a new configuration file wwwblog.conf
and server_name
set it to www.lzxjack.top
:
In this way, /etc/nginx/vhost
there are two configuration files in the directory, blog.conf
and wwwblog.conf
:
Open /etc/nginx/
the nginx.conf
file in the directory and add the following line of code to import the newly created configuration file. *.conf
It means to import vhost
all .conf
the files with the suffix under the folder . Note: to write in http{}
the inside.
include /etc/nginx/vhost/*.conf;
At this point, the configuration of nginx routing is completed, and the domain name and the specified path of the cloud server are bound.
3.4 Install node.js
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs
Execute after the installation is complete node -v
and npm -v
if the version number is printed, the installation is successful
Fourth, configure Git
The main purpose of this part is that the local computer can ssh
connect to the cloud server through the method, and then the blog can be uploaded to the server through the command line.
4.1 Install Git
yum install git
4.2 Configure Git user
Add a Git user:
adduser git
Modify user permissions:
chmod 740 /etc/sudoers
Open /etc/sudoers:
vi /etc/sudoers
Add the statement at this location:
git ALL=(ALL) ALL
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
4.3 Configure Git key
Generate a public key key file:
ssh-keygen
After inputting, press Enter! ! !
At this time, there will be two files in the directory, namely id_rsa
and id_rsa.pub
, among which id_rsa.pub
is the public key file, copy one:
cp id_rsa.pub authorized_keys
There will be a authorized_keys
file in the directory, modify its permissions:
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
The client generates the key:
In the local computer 's CMD
command-line tool input ssh-keygen -t rsa
, press Enter to all! The key will be generated under the user folder of the local computer:
Then, id_rsa.pub
copy the content of the file on the local computer to authorized_keys
the end of the file on the cloud server ! ! ! ! The available methods are:
- Copy content directly
- By
Xftp
file transfer tool, the first local computerid_rsa.pub
files to a location server cloud, the cloud server then on the position executioncat id_rsa.pub >> ~/.ssh/authorized_keys
to
Then we open cmd on the local computer, use the ssh
method to connect to the cloud server, and enter:
ssh -v git@云服务器的公网IP
The last prompt Welcome to Alibaba Cloud Elastic Compute Service !
indicates that the login is successful without entering a password , that is, the configuration of the Git key is successful, and there is no need to enter the Git password when updating the blog deployment in the future!
4.4 Create a Git repository
Create a Git repository and create a new post-receive
file
cd ~
git init --bare blog.git
vi ~/blog.git/hooks/post-receive
Enter the following:
git --work-tree=/home/www/website --git-dir=/home/git/blog.git checkout -f
Save and exit and grant executable permissions to the file
chmod +x ~/blog.git/hooks/post-receive
The server configuration is now complete.
Five, configure hexo, deploy and release
After the local computer and server configuration are completed, in the Hexo root directory of the local computer , enter the following to install the plug-in:
npm install hexo-deployer-git --save
npm install hexo-server
Open the _config.yml
file and modify the deploy
items as follows:
deploy:
type: git
repo: git@云服务器公网IP:/home/git/blog.git
branch: master
Where type
term represents the type of deployment git
, warehouse repo
address git@云服务器公网IP:/home/git/blog.git
, branch branch
to master
the main branch.
After beautifying the blog, adding features, writing articles, etc., the command line input hexo clean
clears the local cache, input hexo g -d
generates static files, and deploys to the remote warehouse.
At this point, the local blog page has been deployed to the server's /home/www/website
directory:
After the deployment is complete, if the open page does not change, you can enter the following restart on the cloud server nginx
:
nginx -s reload
At this point, building a blog through hexo and deploying it to the Alibaba Cloud server is finally complete!
Reference address for the construction process:
Build Hexo blog from scratch and deploy Alibaba Cloud server (nanny-level teaching)