hexo博客部署
Hexo 博客部署指南
本文档记录在 Ubuntu 22.04 服务器上部署 Hexo 博客的完整流程。
快速部署
直接使用一键部署脚本:
1 | wget http://115.29.231.140/shell/hexo-auto-deploy.sh |
环境准备
安装 nvm
1 | git clone https://gitee.com/mirrors/nvm.git ~/.nvm |
安装 Node.js 24 LTS
1 | export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/ |
安装 Hexo
1 | npm config set registry https://registry.npmmirror.com |
配置主题
安装 Butterfly 主题
1 | git clone -b master https://gitee.com/immyw/hexo-theme-butterfly.git themes/butterfly |
启用主题
修改 _config.yml:
1 | theme: butterfly |
配置 Live2D
安装插件和模型
1 | npm install --save hexo-helper-live2d live2d-widget-model-tororo |
配置 Live2D
在 _config.yml 添加:
1 | live2d: |
配置静态资源压缩
1 | npm install --save hexo-neat |
在 _config.yml 添加:
1 | neat_enable: true |
图片压缩
安装 tinypng CLI
1 | npm install -g tinypng-cli |
配置 API Key
1 | echo 'export TINYPNG_KEY="your_key"' >> ~/.bashrc |
压缩图片
1 | tinypng source/img |
进程管理
安装 pm2
1 | npm install -g pm2 |
创建启动脚本
1 | cat > ~/hexo-blog/start.sh << 'EOF' |
启动博客
1 | pm2 start ~/hexo-blog/start.sh --name "hexo-blog" |
配置 Nginx
1 | cat > /etc/nginx/sites-available/hexo << 'EOF' |
常用操作
新建文章
1 | cd ~/hexo-blog |
放入 markdown 文件
1 | # 把 md 文件放到 source/_posts/ 目录 |
pm2 常用命令
1 | pm2 status # 查看状态 |
一键部署
直接运行以下命令即可完成全部部署:
1 | wget http://115.29.231.140/shell/hexo-auto-deploy.sh |
部署脚本会自动完成以下操作:
- 更新系统并安装基础依赖
- 安装 nvm 和 Node.js 24 LTS
- 配置 npm 国内镜像
- 安装 hexo-cli 和 pm2
- 拉取并解压博客压缩包
- 安装所有依赖和插件(Butterfly、Live2D、hexo-neat 等)
- 配置 nginx
- 启动博客并设置开机自启
部署完成后,访问 http://你的服务器IP/hexo 即可查看博客。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 !