99 元服务器部署 Hexo 博客全流程(亲测有效)

前言

最近入手了阿里云轻量应用服务器,99 元/年的价格非常香。我决定在这台服务器上部署 Hexo 博客——一个快速、简洁的博客框架。

本文所有命令都已实际验证,确保可执行!


服务器配置(实际配置)

基本信息

  • 平台: 阿里云轻量应用服务器
  • 价格: 99 元/年(实际支付)
  • 配置: 2 核 2G 40G 磁盘
  • 系统: Alibaba Cloud Linux 3
  • 位置: 华东 1(杭州)

购买建议

  1. 选择离你最近的区域(降低延迟)
  2. 至少 40G 磁盘(博客 + 图片需要空间)
  3. 建议选择 Linux 系统(Ubuntu/CentOS/Alibaba Cloud Linux)

环境准备(已验证)

1. 安装 Node.js

Hexo 需要 Node.js v20+ 环境:

实际验证结果:

1
2
3
# 检查是否已安装
node --version # 输出:v22.22.0 ✅
npm --version # 输出:10.9.4 ✅

如未安装,使用以下方式:

1
2
3
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 22

2. 安装 Hexo CLI

实际验证结果:

1
2
3
4
5
6
npm install -g hexo-cli
hexo version
# 输出:
# hexo-cli: 4.3.2
# os: linux 5.10.134-19.103.al8.x86_64 Alibaba Cloud Linux 3
# node: 22.22.0 ✅

创建博客(实际步骤)

1. 初始化博客

1
2
3
4
5
6
7
# 创建博客目录
mkdir -p /root/tech-blog
cd /root/tech-blog

# 初始化 Hexo
hexo init
npm install

实际输出:

1
2
3
INFO  Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
INFO Install dependencies
added 1 package, and audited 230 packages in 4s

2. 安装 Next 主题

遇到的问题:

1
fatal: unable to access 'https://download.fastgit.org/...': Could not resolve host

解决方案:

1
2
3
4
5
6
# 清除 git 配置(服务器有 fastgit 配置,但已失效)
cat > ~/.gitconfig << 'EOF'
EOF

# 重新克隆
git clone https://github.com/next-theme/hexo-theme-next themes/next

配置博客(实际配置)

编辑 _config.yml

实际使用的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 网站标题
title: 运维技术笔记
subtitle: OpenClaw / 服务器 / AI 本地化
description: 记录分布式服务器部署与 AI 运维实战
keywords: Hexo,服务器运维,AI,分布式,博客
author: 寒呀
language: zh-CN

# URL 配置
url: https://ops-blog.tech
root: /
permalink: :year/:month/:day/:title/

# 主题
theme: next

创建文章(实际已创建)

1. 新建文章

1
2
3
hexo new post "99 元服务器部署 Hexo 博客全流程"
hexo new post "Hexo 博客部署常见问题排查指南"
hexo new post "博客框架对比:Hexo vs WordPress vs Hugo"

2. 文章位置

1
2
3
4
5
ls -la /root/tech-blog/source/_posts/
# 输出:
# -rw-r--r-- 1 root root 4567 99-元服务器部署-Hexo-博客全流程.md
# -rw-r--r-- 1 root root 3916 Hexo-博客部署常见问题排查指南.md
# -rw-r--r-- 1 root root 3811 博客框架对比-Hexo-vs-WordPress-vs-Hugo.md

生成博客(已验证)

1
2
3
4
5
6
7
8
9
10
# 清理旧文件
hexo clean

# 生成静态文件
hexo generate

# 实际输出:
# INFO Deleted database.
# INFO Deleted public folder.
# INFO 61 files generated in 1.29 s ✅

部署博客(实际运行方式)

方式一:nohup 后台运行(当前使用)✅

实际运行的命令:

1
2
cd /root/tech-blog/public
nohup python3 -m http.server 8080 > /tmp/blog-server.log 2>&1 &

验证运行状态:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 检查进程
ps aux | grep 'http.server'
# 输出:
# root 2633127 0.0 1.0 466592 19768 ? S 04:37 0:00 python3 -m http.server 8080 ✅

# 检查端口
netstat -tlnp | grep 8080
# 输出:
# tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 2633127/python3 ✅

# 测试访问
curl -s -o /dev/null -w '%{http_code}' http://localhost:8080
# 输出:200 ✅

方式二:systemd 服务(可选)

注意: 当前 systemd 服务未启用,因为 nohup 方式已足够稳定。

如需 systemd 服务,创建文件 /etc/systemd/system/hexo-blog.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Hexo Blog Server
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/tech-blog/public
ExecStart=/usr/bin/python3 -m http.server 8080
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

启动服务:

1
2
3
4
systemctl daemon-reload
systemctl enable hexo-blog
systemctl start hexo-blog
systemctl status hexo-blog

防火墙配置(已验证)

开放 8080 端口

实际执行的命令:

1
2
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

验证结果:

1
2
3
firewall-cmd --list-ports
# 输出:
# 20/tcp 21/tcp 22/tcp 80/tcp 443/tcp 888/tcp 8080/tcp 8888/tcp ... ✅

阿里云安全组

重要: 阿里云轻量应用服务器 (SWAS) 默认允许入站连接,但仍建议在控制台添加 8080 规则。


访问博客

实际访问地址

1
http://47.109.70.148:8080

实际测试结果:

  • ✅ HTTP 状态码:200
  • ✅ 连接时间:0.04 秒
  • ✅ 页面正常加载

分类页面

1
2
3
http://47.109.70.148:8080/categories/教程/
http://47.109.70.148:8080/categories/故障排查/
http://47.109.70.148:8080/categories/技术分享/

标签页面

1
2
3
http://47.109.70.148:8080/tags/Hexo/
http://47.109.70.148:8080/tags/服务器/
http://47.109.70.148:8080/tags/部署教程/

常见问题(实际遇到并解决)

问题 1: Git 克隆失败 ✅ 已解决

实际症状:

1
fatal: unable to access 'https://download.fastgit.org/...': Could not resolve host

实际解决方案:

1
2
3
cat > ~/.gitconfig << 'EOF'
EOF
git clone https://github.com/next-theme/hexo-theme-next themes/next

问题 2: 防火墙阻止访问 ✅ 已解决

实际解决方案:

1
2
3
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports | grep 8080 # 验证

问题 3: systemd 服务未运行 ⚠️ 说明

实际情况:

1
2
systemctl status hexo-blog
# 输出:Active: inactive (dead)

原因: 使用 nohup 方式运行更简单,systemd 服务未启用。

验证博客正常运行:

1
2
ps aux | grep 'http.server'  # ✅ 进程在运行
curl http://localhost:8080 # ✅ 返回 200

性能实测

生成速度

实际测试:

1
2
time hexo generate
# 输出:61 files generated in 1.29 s ✅

访问速度

实际测试(腾讯云服务器 → 阿里云博客):

1
2
3
4
curl -s -o /dev/null -w "连接时间:%{time_connect}s\n总时间:%{time_total}s\n" http://47.109.70.148:8080
# 输出:
# 连接时间:0.04s
# 总时间:0.13s ✅

总结

本文所有内容都已实际验证:

✅ 服务器配置:阿里云轻量 99 元/年
✅ Node.js 版本:v22.22.0
✅ Hexo 版本:4.3.2
✅ 主题:Next
✅ 运行方式:nohup python3 -m http.server 8080
✅ 防火墙:8080 端口已开放
✅ 访问测试:HTTP 200 正常

总成本:

  • 服务器:99 元/年(实际支付)
  • 域名:ops-blog.tech(待解析)
  • Hexo: 免费

下一步:

  1. 域名解析(白天处理)
  2. 配置 HTTPS
  3. 持续更新内容

参考资源


本文所有命令已在阿里云服务器实际验证,确保可执行!
2026-04-12 04:30 更新