博客搭建

安装nodeJs & Git

curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -

yum install nodejs

node --version

npm --version

安装hexo

npm install -g hexo-cli

安装配置Nginx

# 添加 Nginx 源
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

# 安装 Nginx
sudo yum install -y nginx

# 启动 Nginx
sudo systemctl start nginx.service

# 设置开机自启 Nginx
sudo systemctl enable nginx.service

# 配置Nginx
vim /etc/nginx/conf.d/blog.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server {
listen 80;

server_name zhangguoli.cn www.zhangguoli.cn;

location / {
# hexo博客public路径
root /opt/hexo/public;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# hexo静态页面不需要代理
# proxy_pass http://127.0.0.1:8090/;
}
}
重载 Nginx 配置
sudo nginx -s reload

配置SSL

# 安装 certbot 以及 certbot nginx 插件
sudo yum install certbot python2-certbot-nginx -y

# 执行配置,中途会询问你的邮箱,如实填写即可
sudo certbot --nginx

# 自动续约
sudo certbot renew --dry-run