惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
TaoSecurity Blog
TaoSecurity Blog
Schneier on Security
Schneier on Security
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
O
OpenAI News
W
WeLiveSecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
S
Security @ Cisco Blogs
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
博客园 - 司徒正美
B
Blog RSS Feed
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker
Google Online Security Blog
Google Online Security Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
月光博客
月光博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件

Dejavu's Blog

甲骨文 ARM 实例部署 Gemma 4 模型 Headscale + Tailscale 组建虚拟专用网 在 Linux 上使用 Yubikey OpenPGP 应用 BuyVM VPS 块存储挂载教程 Alpine Linux 服务器配置指南 Alpine Linux 安装 Cloudflared Docker 多容器共享中心数据库 安装 Komari 服务器监控工具 Scaleway VPS 安装 Debian Linux Debian 13 下部署 AsmBB 论坛 使用 Kopia 自动化备份服务器数据 给 Docker 启用 IPv6 支持 Netcup 服务器安装自定义 ISO 镜像 烽火 HG5582A 光猫开启桥接模式 Docker 自托管 Shlink 短链服务 部署 Obsidian LiveSync 实时同步服务指南 我的 2025 年不完全回顾 Linux 下 Intel 核显驱动配置与硬件加速 Fedora Linux 安装配置记录 2025 年优雅地自托管 RSS 服务 Gitea/Forgejo 集成 Woodpecker CI/CD 在 Blinko 中使用 Ollama 作为 AI 供应商 Docker 部署 Gitea/Forgejo Plausible CE 启用城市级地理位置识别 Blinko 开源 AI 知识库 Docker 部署指南 Netcup 免税账号注册及购买服务器全记录 Docker 自托管 Cloudreve Pro 私有网盘服务 GiffGaff SIM 卡使用体验和注意事项 简体中文互联网在变得糟糕吗? 如何低成本申请 S/MIME 证书用于个人邮件服务 迁移到 NameCrane Mail 域名邮箱套件服务 香烟与咖啡 在 Windows 中使用 Yubikey 的 OpenPGP 应用 Windows 11 IoT LTSC 养老指南 巧用浏览器生成 HAR 文件批量下载所需网页资源 聊聊静态网站的评论系统 在 Hugo 站点中优雅地展示实况照片 使用 snac 部署一个简洁优雅的 ActivityPub 实例 当 25 岁来临的时候 断网的这两年 从 Bitwarden/Vaultwarden 到 KeePassXC 也许是 Android 上最好的本地播放器 - 椒盐音乐 2023 半年小结 写一个好玩的 Hugo 货币汇率转换短代码 写一个 Hugo 短代码将不同类别的总字数统计转换为书名显示 海信 Touch Lite 墨水屏音乐阅读器的简单体验 从 Debian 11(bullseye) 无感升级到 Debian 12(bookworm) 使用 GitHub Actions 自动提交 URL 到 IndexNow 批量重写 Git 历史提交记录 使用 cgit 托管小小的也很可爱的 Git 服务器 在 Debian 上使用 stagit 和 Nginx 的简单 Git 服务器 托管简单 Git 服务器的一些尝试 使用 stagit 自托管纯静态 Git 存储库 使用 Docker 快速部署单人 Fediverse 实例 我是如何建立自己的个人博客的? 简单、隐私友好的谷歌分析替代品,Plausible 自托管部署指南 服务器使用 Cloudflare CDN 的最佳实践 甲骨文服务器分配并启用 IPv6 地址 Git 版本控制学习笔记(二) Cloudflare WAF 防护策略简易指南 Mastodon 服务器批量导入自定义表情 低成本自托管 Mastodon 实例简明指南 自托管服务指南──有了服务器可以做什么? 使用 Miniflux + RSSHub 打造个人 RSS 阅读器 构建支持多种 CPU 架构的 Docker 镜像 一个可自托管的静态短链接应用 别了,二〇二二! Duplicacy CLI 进阶使用指南 Duplicacy CLI 备份工具的基本使用 初探 Cloudflare 零信任 - 通过 Docker 部署 Bitwarden 密码管理器 Yubikey 转运日志及上手指南 初探 Cloudflare 零信任 — 通过 Cloudflare Tunnel 搭建 SSH 聊天室 初探 Cloudflare 零信任 - 通过 Cloudflare Tunnel 访问服务 某科学的 PGP 算号指南 2022 年的 MacBook Air M1 使用体验及应用推荐 使用 Vercel 和 Supabase 自托管 Cusdis 评论系统 为什么你的搜索引擎不好用? 个人在 Windows 上常用软件清单 macOS 基础开发环境设置指南 在 macOS 上使用 Canokey 的 OpenPGP 应用 提取 Windows UWP 应用商店的安装包以供离线安装 Git 版本控制学习笔记(一) 使用 Notion 管理 GitHub Star 项目 使用 Vercel 免费部署 Giscus 评论系统 将博客评论从 Utterances 无缝迁移到 Giscus Canokey 签名和认证应用指南 Canokey 的基本使用指南 Canokey Pigeon 揽件日志及简单开箱 关于 Google Play 保护机制和 DRM 安全等级的那些事 记录一次捡垃圾装机 GitHub 使用 GPG 密钥提交签名认证 使用 Scoop 管理 Windows 下的软件和开发环境 Windows Terminal+PowerShell 7 打造 Windows 下最好用的终端 一个好用的 Telegram 文件批量上传/下载工具 Clash for Windows 优雅地使用 TUN 模式接管系统流量 全平台搭建 Hexo 静态博客指南 尝试将 Manjaro 作为主力操作系统使用 Hexo 进行 SEO 优化的基本指南 使用本地代理给 Git 和 NPM 加速 使用 flowerss 部署 Telegram RSS 订阅机器人
Woodpecker CI 和 Gitea 实现 Hugo 自动部署
Dejavu Moe · 2025-12-03 · via Dejavu's Blog

前言

今天经过了一些尝试,我终于是把博客从 Cloudflare Pages 迁移到了自己的服务器上,整个过程对访客应该是无感的,无缝切换?Who Knows?

不是必要的准备工作:

将 GitHub 存储库作为备份,另外给博客源代码添加一个远程存储库 URL

检查一下

嗯,现在一次 Git Push 会同时推送到 GitHub 和自己的 Gitea 存储库,这样就好了。

编写 Workflow

整个 Workflow 比较简单暴力,缺乏安全和性能上的考虑,后面碰到具体问题再补充吧。进入 Hugo 根目录添加 .woodpecker/hugo-build-site.yml,大概如下:

when:
  event:
    - push
  branch:
    - master

steps:
  - name: build hugo site
    image: hugomods/hugo:dart-sass-git-0.155.1
    volumes:
      - /tmp/hugo_cache:/tmp/hugo_cache
      - /var/www:/var/www
    commands:
      - rm -rf /var/www/yourblog/html/*
      - hugo --minify -d /var/www/yourblog/html

  - name: site deploy
    image: alpine:3.20
    commands:
      - echo "site build success,update path /var/www/yourblog/html"

  - name: purge-cdn
    image: curlimages/curl:8.18.0
    environment:
      CF_PURGE_CACHE_API_TOKEN:
        from_secret: CF_PURGE_CACHE_API_TOKEN
      CF_ZONE_ID:
        from_secret: CF_ZONE_ID
    commands:
      - echo "purge Cloudflare CDN cache for blog ..."
      - |
        curl -sS "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/purge_cache" \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $CF_PURGE_CACHE_API_TOKEN" \
          -d '{"hosts":["blog.your.domain"]}'

开头的 when 定义执行条件,即:当存储库有 pushmaster 分支时,开始执行。steps 里描述具体执行哪些步骤:

  1. 构建 Hugo 网站
  2. 打印构建结果(可选)
  3. 清除 CDN 缓存(注意修改主机名)

配置 Nginx

添加一个 Nginx 虚拟主机配置,用于直接提供静态网页服务

server {
    listen 80;
    listen [::]:80;
    server_name blog.your.domain;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name blog.your.domain;

    ssl_certificate /path/to/cert/blog.your.domain.pem;
    ssl_certificate_key /path/to/cert/blog.your.domain.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ecdh_curve X25519:P-256:P-384;
    ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE+AES128:RSA+AES128:ECDHE+AES256:RSA+AES256';
    ssl_prefer_server_ciphers off;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    access_log /var/log/nginx/blog.your.domain.access.log;
    error_log /var/log/nginx/blog.your.domain.error.log;

    root /var/www/blog.your.domain/html;
    index index.html;
    error_page 404 /404.html;

    proxy_set_header X-Forwarded-For $realip_remote_addr;

    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "no-referrer-when-downgrade" always;
    add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;

    gzip on;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_types text/plain text/css text/javascript application/javascript application/json application/xml application/rss+xml application/wasm;
    gzip_vary on;

    location = /404.html {
    internal;
    }

    location ~* \.html$ {
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-XSS-Protection "1; mode=block" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Referrer-Policy "no-referrer-when-downgrade" always;
        add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
        add_header Cache-Control "no-cache, no-store, must-revalidate";
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png|webp|woff2?|ttf|svg|eot|mp4|webm)$ {
        access_log off;
    }

    location / {
        try_files $uri $uri/ =404;
    }

}

需要注意的是,上面没有添加任何 Nginx 缓存配置,实际上应当需要设置合理的缓存。但我对此还不是很了解,暂时就用 CDN 自定义缓存规则替代吧。

获取环境变量

如果需要第三步,需要在 Cloudflare 创建一个最小权限的 API Token

create-api-key.webp

设置自定义令牌的权限,如果可以请尽可能加上服务器的 IP 作为客户端限制

configure-api.webp

复制博客使用域名的区域 ID

zone-id.webp

上面会获取两个机密

  • CF_PURGE_CACHE_API_TOKEN
  • CF_ZONE_ID

在 Woodpecker 仪表盘添加博客存储库,在该存储库设置里添加上面两个 Secret,应该给 Push 作用域就够用了

add-secret.webp

设置信任卷挂载

trust-volume.webp

在 Woodpecker 容器的 Compose 模板,添加构建的静态网站输出目录

  woodpecker-agent:
    image: woodpeckerci/woodpecker-agent:v3
    container_name: woodpecker-agent
    restart: unless-stopped
    # ...
    # only for woodpecker-agent
    # ...
    volumes:
      # ...
      # add this(for example)
      - /var/www:/var/www
      # ...

然后更新容器

sudo docker compose up -d

部署上线

尝试推送一次博客更新,构建速度非常快!

success.webp

结语

总之,这是一次成功的尝试,过程还算顺利(也就失败了十几次而已😅)。访问速度不一定比 Cloudflare Pages 更好,但是好在再也没有构建次数限制了。

参考资料: