Hexo的部署使用——基础部署一
Hexo搭建步骤
1、安装Git
2、安装Node.js
3、安装Hexo
4、安装nginx
一、安装Git
git作用:用来管理hexo博客文章,上传到github的工具
安装命令:
yum -y install git-core
安装好后,用git –version确认版本
二、安装Node.js
1、先从官网下载node.js的压缩包
wget https://nodejs.org/dist/v12.16.0/node-v12.16.0-linux-x64.tar.xz
2、解压到/opt目录下
tar -xvf node-v12.16.0-linux-x64.tar.xz -C /opt/
3、为了简洁,将目录重命名
cd /opt/
mv node-v12.16.0-linux-x64 nodejs
4、修改环境变量
vi /etc/profile
在该配置文件下添加以下内容
PATH=/opt/nodejs/bin:$PATH
5、重新加载配置文件,使其生效
source /etc/profile
6、进行验证
1
2
3
4[root@VM-0-6-centos _posts]# node -v
v12.16.0
[root@VM-0-6-centos _posts]# npm -v
6.13.4
三、安装Hexo
1、安装hexo程序
npm install hexo-cli -g
2、到指定的目录下部署hexo(比方说/home/hexo)
mkdir /home/hexo && cd /home/hexo
3、在当前目录下建立网站
hexo init
4、生成静态文件
hexo g
四、安装nginx
1、nginx简介
nginx是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务
其特点是占有内存少,并发能力强
2、nginx安装
yum -y install nginx
3、nginx配置
vim /etc/nginx/nginx.conf
在该配置文件中,首次部署可以只关注server部分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23server {
listen 80;
listen [::]:80;
server_name _; #server_name后配置的是域名,只有一个下划线代表不启用域名
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / { #在该部分新增location块,该location块指定/与来自请求的URI相比较的前缀
root /home/hexo/public; #该字段配置的是生成的静态文件所在的目录位置
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
4、令nginx配置生效
nginx -s reload
#热启动,不重启nginx服务,只是重新读取配置
五、进行验证
由于已经配置过nginx,直接用 http://公网ip/ 即可访问