1 安装Hexo
1.1 安装依赖
1.1.1 安装npm
1.1.2 安装nvm
Debian安装npm时会自动安装Node,但Debian安装的版本一般比较低,如果运行最新版本的Hexo会报错。
所以这里还需要安装nvm来管理多个版本并安装合适版本的Node。
1 2 3 4 5 6 7 8
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm
|
1.1.3 使用nvm安装Nodejs 20 LTS
1 2 3 4 5 6 7 8 9 10 11 12 13
| nvm list-remote
nvm install 20
nvm use 20
|
1.2 安装Hexo
1.2.1 使用npm全局安装hexo-cli
1.2.2 验证安装情况
1.2.3 创建Hexo目录并初始化Hexo
1 2 3 4 5
| mkdir /opt/hexo && cd /opt/hexo
hexo init
|
1.2.4 运行Hexo
2 使用pm2管理Hexo后台运行
2.1 安装pm2
2.2 编写pm2要执行的脚本
在hexo目录下创建文件hexo.js
hexo.js中编写管理脚本
1 2 3 4 5 6 7 8 9
| const { exec } = require('child_process') exec('hexo s -p 4000',(error, stdout, stderr) => { if(error){ console.log('exec error: ${error}') return } console.log('stdout: ${stdout}'); console.log('stderr: ${stderr}'); })
|
2.3 使用pm2执行脚本管理Hexo
1 2 3 4 5
| # 开启服务 pm2 start hexo.js
# 停止服务 pm2 stop hexo.js
|
3 使用Nginx配置反向代理
3.1 创建配置文件
1 2
| vim /etc/nginx/conf.d/hexo.conf
|
3.2 编辑文件配置反向代理
1 2 3 4 5 6 7 8 9 10 11
|
server { listen 443 ssl; server_name guolog.ink www.guolog.ink;
location / { proxy_pass http://localhost:4000; } }
|
3.3 使用Nginx配置SSL
nginx配置SSL只需要在配置文件内添加上两行配置分别指定SSL的cert和key文件就行。
在配置反向代理的文件内添加。
1 2
| ssl_certificate /usr/local/nginx/ssl/cert.pem; ssl_certificate_key /usr/local/nginx/ssl/key.pem;
|
最终得到Nginx新增的配置文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
| #hexo配置
server { listen 443 ssl; server_name guolog.ink www.guolog.ink;
ssl_certificate /usr/local/nginx/ssl/cert.pem; ssl_certificate_key /usr/local/nginx/ssl/key.pem;
location / { proxy_pass http://localhost:4000; } }
|