前言

最近入手了阿里云轻量应用服务器,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
4
5
6
7
8
# 检查是否已安装
node --version # 应显示 v22.x.x
npm --version # 应显示 10.x.x

# 如未安装,使用以下方式
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
npm install -g hexo-cli
hexo version # 验证安装

创建博客

1. 初始化博客

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

# 初始化 Hexo
hexo init
npm install

2. 安装 Next 主题

1
2
# 克隆 Next 主题
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
hexo new post "99 元服务器部署 Hexo 博客全流程"

2. 编辑文章

文章位于 source/_posts/ 目录,使用 Markdown 格式:

1
2
3
4
5
6
7
8
9
---
title: 文章标题
date: 2026-04-12
tags: [标签 1, 标签 2]
categories: 分类
---

## 正文内容
...

生成博客

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

# 生成静态文件
hexo generate

# 启动本地预览
hexo server -p 4000

部署博客

方式一:Python HTTP 服务(简单)

1
2
3
4
5
6
7
# 进入 public 目录
cd /root/tech-blog/public

# 启动 HTTP 服务
nohup python3 -m http.server 8080 &

# 访问:http://服务器IP:8080

方式二:systemd 服务(推荐)

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

1
2
3
4
5
6
7
8
9
10
11
12
13
[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

[Install]
WantedBy=multi-user.target

启动服务:

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

常见问题

问题 1: Git 克隆失败

症状: 无法访问 github.com

解决:

1
2
3
4
5
6
# 清除 git 配置
cat > ~/.gitconfig << 'EOF'
EOF

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

问题 2: 端口被占用

症状: 8080 端口无法启动

解决:

1
2
3
4
5
6
7
8
# 查找占用端口的进程
netstat -tlnp | grep 8080

# 杀死进程
kill -9 <PID>

# 或者换端口
python3 -m http.server 8081

问题 3: 防火墙阻止访问

解决:

1
2
3
4
5
6
# 开放端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

# 验证
firewall-cmd --list-ports | grep 8080

性能优化

1. 启用缓存

Next 主题支持 PWA 缓存,提升访问速度。

2. 图片优化

使用 WebP 格式,压缩图片大小。

3. CDN 加速

使用 Cloudflare 或阿里云 CDN 加速静态资源。


总结

至此,Hexo 博客已经成功部署在你的 99 元服务器上了!

总成本:

  • 服务器:99 元/年
  • 域名:可选(约 50 元/年)
  • Hexo: 免费

下一步:

  1. 配置自定义域名
  2. 申请 HTTPS 证书
  3. 持续更新内容

参考资源


如有问题,欢迎在评论区留言!

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

0%