用 Hugo 搭建个人博客:从零到上线
一份可复现的 Hugo 静态博客搭建流程,涵盖主题、内容与部署。
静态博客的核心思路是:写作时生成 HTML,线上只负责分发文件。相比动态博客,它不需要数据库,攻击面小,也不需要为每次访问做渲染。
目录结构
blog/
├── hugo.yaml # 站点配置
├── content/ # Markdown 原文
│ ├── about.md
│ └── posts/
├── themes/minimal/ # 自定义主题
│ ├── layouts/
│ └── static/
└── public/ # 构建产物(Nginx 根目录)
写作
新建一篇文章:
hugo new posts/my-post.md
在 Markdown 顶部填写 front matter:
---
title: "文章标题"
description: "摘要"
date: 2026-11-20
categories: ["技术"]
tags: ["Hugo"]
---
构建与预览
hugo server -D # 本地预览
hugo --cleanDestinationDir --destination public
Hugo 默认不会渲染 draft: true 的文章,预览时加 -D 即可。
部署
把 public/ 设为 Nginx 的 root,并配置 HTTPS。证书使用 Let’s Encrypt 的 DNS-01 验证方式即可,无需在 80 端口开放验证文件。
server {
listen 443 ssl;
server_name blog.example.com;
root /var/www/blog/public;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
}
小结
| 环节 | 工具 | 备注 |
|---|---|---|
| 写作 | Markdown | 纯文本,便于版本管理 |
| 构建 | Hugo | 秒级生成 |
| 分发 | Nginx | 静态文件,资源占用低 |
| 加密 | Certbot | 支持自动续期 |
这套方案的维护成本主要集中在内容本身,基础设施基本可以"搭好后忘掉"。