1. Installation Preparations (Local Mac)
- Git
- node.js
- hexo
Install Git
Git is easy to install on your Mac
Installation node. Js
After a long time trying to install it on the server (centos7), I found an easier way to recommend:
$wget - qO - https://raw.github.com/creationix/nvm/v0.33.11/install.sh | shCopy the code
After the installation is complete, restart the terminal and run the following command to install Node.js.
$ nvm install stable
Copy the code
After the installation is successful, enter node -v to check whether the installation is successful.
Install Hexo and plugins:
npm install hexo-cli hexo-server hexo-deployer-git -g
Copy the code
Blogging with Hexo (local)
1. Run the following command on the terminal after installing Hexo:
$ hexo init <folder>
$ cd <folder>
$ npm install
Copy the code
is the name of the folder. If you do not enter it, the current folder (must be empty). If it works, by this point our blog has been set up locally.
- _config.yml: is a configuration file for the entire hexo, which can be opened using text. Note that the value of each parameter is modified
:
With the same guyThe blank space, cannot run successfully without Spaces. - Source /_posts: this is the directory where all the md files are located
2. Then you can use the theme Next to beautify your site.
Deploy the server
Purchase server + domain name
You can choose Ali cloud and Tencent cloud to buy such as: www.maaiting.com, after the purchase of the site quickly real name system. Buy the cheapest configuration is ok, cloud server about 300 more than a year.
Here make fun of Tencent cloud in my purchase after the server called me to install the graphics card driver????
After the purchase, speak domain name quickly real-name system, in wechat small program Tencent cloud assistant record (this will be much faster). After passing Tencent’s approval (within a day, you will be called to confirm), the domain name will be displayed normally.
Locate the domain name resolution and resolve the domain name. It’s all a fool operation. Don’t be afraid to be bold.
Deploy using Nginx
My server is CentOS 7.2 operating system, using Nginx deployment.
Log in to the server as root. 2. Install Git Nginx
yum -y update
yum install -y git nginx
Copy the code
3. Configure Nginx, create a directory and set permissions to store blog files.
cd /usr/local/
mkdir hexo
chmod 775 -R /usr/local/hexo/
Copy the code
4. Add the test index. HTML file to check whether the configuration is successful
vim /usr/local/hexo/index.html
Copy the code
<! DOCTYPE html> <html> <head> <title></title> <meta charset="UTF-8"> </head> <body> <p>Hello,Make! Nginx is running! </p> </body> </html>Copy the code
5. Configure the Nginx server
vim /etc/nginx/nginx.conf
Copy the code
Change the value below port 80
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.maaiting.com; # 填写个人域名
root /usr/local/hexo/; #hexo文件目录
}
Copy the code
6. Start
service nginx start
Copy the code
Enter your domain name to see if the contents of index.html are rendered.
Configuring the Git Environment
1. Create a personal directory and set up a Git repository. Set read and write permissions
cd /usr/local/
mkdir blogRepo
chmod 775 -R /usr/local/blogRepo/
Copy the code
2. Initialize the Git repository
cd blogRepo/
git init --bare hexo.git
Copy the code
3. Create Git hook
vim /usr/local/blogRepo/hexo.git/hooks/post-receive
Copy the code
Paste the following code block:
#! /bin/bash git --work-tree=/usr/local/hexo --git-dir=/usr/local/blogRepo/hexo.git checkout -fCopy the code
Press ESC+:wq to save
4. Grant permissions
chmod +x /usr/local/blogRepo/hexo.git/hooks/post-receive
Copy the code
3. Local configuration
Configuring local Files
Locate the hexo file initialized in the first step of preparation, locate the _config.yml file, open it with text, and modify the following information:
# URL ### If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' url: https://www.maaiting.com // Personal domain name...... Deploy # # # # Deployment Docs: https://hexo.io/docs/deployment.html: / / release the corresponding lot account type: git # such as: [email protected]: / usr/local/bogRepo/hexo repo: [email protected]: / usr/local/blogRepo hexo / / user name @ domain name or IP address: / usr/local/blogRepo/hexo branch: masterCopy the code
Deploy the local configuration to the server
1. CD into the created local Hexo directory as follows:
cd ~/Desktop/blog
Copy the code
2. Generate a static page and deploy it to the server:
hexo g && hexo d
Copy the code
Enter your domain name or Internet IP to view the blog.
Three.SEO related optimization
SEO optimization is to be faster and more included by search engines, your website is easier to be searched on Baidu and Google.
Deploy the HTTPS
Take Tencent Cloud as an example:
-
Go to SSL Certificates – Certificate Management – Apply for free certificates (you can come down in about an hour)
-
Download the certificate. There are certificates in different configurations. The following uses Nginx as an example.
-
Create an SSL directory on the server to store the certificate
cd /etc/nginx mkdir ssl Copy the code
-
Run the SCP command to upload the local certificate to the SSL directory on the server
Sudo SCP - r/Users/make/Downloads/maaiting/Nginx/[email protected]: / etc/Nginx/SSL /Copy the code
-
Operates on the server to redirect HTTP to HTTPS
cd /etc/nginx vim nginx.conf Copy the code
Add code under port 80: rewrite ^(.*) https://$server_name$1 permanent; Such as:
server { listen 80 default_server; listen [::]:80 default_server; server_name www.maaiting.com; /usr/local/hexo/ # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; rewrite ^(.*) https://$server_name$1 permanent; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }Copy the code
Add below:
server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; server_name www.maaiting.com; root /usr/local/hexo/; ssl_certificate "/etc/nginx/ssl/1_maaiting.com_bundle.crt"; ssl_certificate_key "/etc/nginx/ssl/2_maaiting.com.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:! aNULL:! MD5; ssl_prefer_server_ciphers on; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }Copy the code
-
Restart the Nginx
systemctl restart nginx Copy the code
Enter the domain name again and you can see that it is automatically directed to HTTPS
sitemap
You can install these plug-ins to automatically generate sitemap
npm install hexo-generator-sitemap
npm install hexo-generator-sitemap --save-dev
npm install hexo-generator-baidu-sitemap --save-dev
Copy the code
And can be used within a topic profile: show sitemap. At the same time, you can submit sitemap on Google Baidu statistics as required.
Menu: home: / | | home # about: / about / | | all article: user/archives / | | archive categories: / categories / | | th tags: /tags/ || tags #schedule: /schedule/ || calendar sitemap: /sitemap.xml || sitemap #commonweal: /404/ || heartbeatCopy the code
Sites submitted
You can submit the url to Baidu here, the url included faster oh.
You can also submit it to Google here.