关联主题:: 博客加速访问的方案探索和学习
同级:: 2025-08-24_星期日
下一级::


整体架构:

GitHub (源代码) 
     │
     │  GitHub Action 自动构建
     ▼
阿里云 OSS(对象存储) 
     │
     │  阿里云 CDN 加速
     ▼
用户访问(国内 CDN 节点)← 免费 DNS(DNSPod / 腾讯云解析)

具体的操作,我是在Dia浏览器对话下一步步完成的。

优先选择的是腾讯云,一方面是我域名是在腾讯云买的,另一方面Dia的AI分析说,腾讯云较阿里云便宜

1、登录腾讯云,搜索对象存储COS
地址: https://cloud.tencent.com/product/cos

AI推荐我直接使用“标准存储(单AZ)”即可。

面向一份纯静态的 Quartz 博客,最重要的衡量标准其实只有三项:

  1. 访问是否“足够快”——首字节延迟、静态文件下载速度。
  2. 数据是否“够安全”——单可用区失效时能否自动容灾。
  3. 钱包是否“能接受”——每个月几块钱还是十几块钱的差距。

为什么个人博客多数人选“标准存储”而非“多 AZ” 

  1. 流量远大于容量:静态站常见 200 MB–1 GB 体积,真正的大头是 CDN 下行流量费,存储费只占个位数百分比。
  2. 域名 + CDN 已做跨机房:CDN 节点遍布全国,哪怕源站短暂故障,边缘节点仍能回源其他副本或继续回放缓存。
  3. 代码托管在 GitHub:即便极端情况下桶损坏,你也可重新构建并全量上传;“绝对不可丢”的业务数据很少。

主要我的项目同时存在于本地、Github、Nas,所以并不担心丢失的问题。

2、购买对象存储和CDN资源包

具体消费价格:

  1. COS 对象存储(买的10个G),按月购买0.85元;
  2. 内容分发网络CDN-中国境内CDN流量包,20G流量/年,价格20.85;

不需要购买数据处理资源包,但建议购买或领取免费CDN流量包。

3、创建存储桶

  1. 登录 腾讯云对象存储控制台 ↗

  2. 点击「存储桶」→「新建存储桶」。

    • 地域选择与你目标用户接近的城市(如北京、上海、广州)。
    • 存储类型选“标准存储”。
    • 权限保持默认“私有读写”。
  3. 创建后,进入存储桶详情页,找到「静态网站托管」功能,点击开启。

    • 主页文件填写 ‎index.html
    • 404页面填写 ‎404.html(如果有)

4、准备两样东西

  1. 腾讯云密钥:‎SecretId 和 ‎SecretKey
  2. 存储桶信息:‎Bucket 名称和所在 ‎Region(如 ‎blog-125xxxx ap-beijing
    这两样是 GitHub 用来连接 COS 的“钥匙”。

5、开启「静态网站托管」 

  1. 进入 对象存储 COS → 存储桶列表,点进你刚创建的桶。
  2. 左侧菜单找到 静态网站,点 编辑 / 开启
  3. 在弹窗中填写:
    • 主页:‎index.html
    • 404 页面:‎404.html(若没有可留空)
  4. 点击 保存。界面会立刻显示一个测试域名,形如
http://blog-125xxxx.cos-website.ap-beijing.myqcloud.com

这就是你暂时的访问地址,无需备案即可打开。
5. 确认桶已开启 静态网站托管,主页是 ‎index.html

cm:但是似乎根据新规定,这个默认的域名无法预览内容了,只能下载文件…所以无实际价值。

6、首次手动上传文件 
先用网页控制台完成一次上传,确认流程通顺,再做自动化。

  1. 在同一存储桶的 文件列表 页面,点击 上传 上传文件夹
  2. 选中本地项目根目录下的 ‎public 文件夹(里面应该有 ‎index.html、‎assets 等)。
  3. 保持“上传到当前路径 / ”不变 → 确定
  4. 上传完成后,浏览器访问上面那串 myqcloud.com 域名,应该就能看到你的博客页面。若出现 404,请检查是否把 ‎index.html 直接放在了根路径,而不是套一层文件夹。

7、Github填写密钥到仓库的secret
GitHub 仓库 → Settings → Secrets → Actions → New repository secret

  • COS_SECRET_ID → 粘贴你的 SecretId
  • COS_SECRET_KEY → 粘贴你的 SecretKey
  • COS_BUCKET → 如 ‎blog-1251234567(带账号 ID)
  • COS_REGION → 如 ‎ap-beijing

8、仓库根目录新建
“.github/workflows/deploy-cos.yml`

这个文件代码,问尝试了好几次都有问题,最后Dia免费额度用完了…我用cursor修改,最终成功上传文件到存储桶了,但还是又报错,初步是可以用了。

# .github/workflows/deploy-cos.yml
name: Deploy to Tencent COS

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Use Node.js 22
      uses: actions/setup-node@v4
      with:
        node-version: '22'

    - name: Checkout code
      uses: actions/checkout@v4

    - name: Upgrade npm
      run: npm install -g npm@latest

    - name: Install dependencies
      run: npm ci

    - name: Build Quartz site
      run: npm run build

    - name: Debug - List public directory contents
      run: |
        echo "=== Public directory structure ==="
        find ./public -type f -name "*.html" | head -20
        echo "=== Checking specific path ==="
        ls -la ./public/1-Article/生活服务/出行安全/ || echo "Path not found"
        echo "=== Checking alternative path ==="
        ls -la ./public/Article/生活服务/出行安全/ || echo "Path not found"
        echo "=== Full directory tree ==="
        tree ./public -L 3 || find ./public -type d | head -20

    - name: Debug - Check file paths in built files
      run: |
        echo "=== Checking for Article references in built files ==="
        grep -r "Article/" ./public --include="*.html" | head -10 || echo "No Article/ references found"
        echo "=== Checking for 1-Article references in built files ==="
        grep -r "1-Article/" ./public --include="*.html" | head -10 || echo "No 1-Article/ references found"

    - name: Create symbolic link for Article directory (temporary fix)
      run: |
        echo "Creating symbolic link to fix path mismatch..."
        cd ./public
        ln -sf "1-Article" "Article"
        echo "Symbolic link created:"
        ls -la Article || echo "Failed to create symbolic link"

    - name: Debug - Check file count and size
      run: |
        echo "=== File count and size information ==="
        echo "Total files in public directory:"
        find ./public -type f | wc -l
        echo "Total size of public directory:"
        du -sh ./public
        echo "Checking for large files (>10MB):"
        find ./public -type f -size +10M | head -10 || echo "No files larger than 10MB"

    - name: Debug - Test COS credentials and connectivity
      run: |
        echo "=== Testing COS connectivity ==="
        echo "COS_BUCKET: ${{ secrets.COS_BUCKET }}"
        echo "COS_REGION: ${{ secrets.COS_REGION }}"
        echo "COS_SECRET_ID: ${{ secrets.COS_SECRET_ID != '' && 'SET' || 'NOT SET' }}"
        echo "COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY != '' && 'SET' || 'NOT SET' }}"

    - name: Test COS connection with curl
      run: |
        echo "=== Testing COS API connectivity ==="
        # Test basic connectivity to Tencent Cloud
        curl -s --connect-timeout 10 "https://service.cos.myqcloud.com" > /dev/null && echo "COS service reachable" || echo "COS service not reachable"
        
        # Test region-specific endpoint
        curl -s --connect-timeout 10 "https://cos.${{ secrets.COS_REGION }}.myqcloud.com" > /dev/null && echo "Region endpoint reachable" || echo "Region endpoint not reachable"

    - name: Upload to COS (with detailed error handling)
      id: upload-cos
      uses: TencentCloud/cos-action@v1
      with:
        secret_id:  ${{ secrets.COS_SECRET_ID }}
        secret_key: ${{ secrets.COS_SECRET_KEY }}
        cos_bucket: ${{ secrets.COS_BUCKET }}
        cos_region: ${{ secrets.COS_REGION }}
        local_path: ./public/
        remote_path: /

    - name: Verify upload success
      run: |
        echo "=== Upload verification ==="
        echo "Checking if files were uploaded successfully..."
        echo "Note: If you see files in your COS bucket, the upload was successful despite the error message"
        echo "The [object Object] error might be a display issue in the action, not an actual failure"
        
        # List some key files to verify they exist
        echo "Checking for key files in public directory:"
        ls -la ./public/1-Article/生活服务/出行安全/ || echo "Key directory not found"
        
        echo "Upload verification completed"

    - name: Upload status summary
      run: |
        echo "=== UPLOAD STATUS SUMMARY ==="
        echo "✅ Files were built successfully"
        echo "✅ Files exist in local public directory"
        echo "⚠️  TencentCloud action showed error but files may have uploaded"
        echo "📋 Check your COS bucket to confirm upload success"
        echo ""
        echo "If files are in your bucket, the deployment was successful!"
        echo "The [object Object] error appears to be a display issue in the action."
        echo ""
        echo "🔍 IMPORTANT: Your bucket was created after 2024-01-01"
        echo "⚠️  Default COS domains don't support file preview for new buckets"
        echo "💡 Solution: Configure custom domain in COS console"

    - name: Custom domain configuration reminder
      run: |
        echo "=== CUSTOM DOMAIN SETUP GUIDE ==="
        echo "To fix the 403 error and enable website access:"
        echo "1. Go to Tencent Cloud COS Console"
        echo "2. Select your bucket: blog-1259712772"
        echo "3. Go to 'Domain Management' → 'Custom Source Domain'"
        echo "4. Add your custom domain (e.g., blog.yourdomain.com)"
        echo "5. Configure DNS to point to Tencent Cloud"
        echo "6. Enable HTTPS certificate (free from Tencent Cloud)"
        echo ""
        echo "After setup, your site will be accessible via custom domain"
        echo "Default COS domain will continue to show 403 errors"



9、提交到Github

git add .
git commit -m "x'x'x"
git push -u origin main

但是无奈,虽然文件上传到了「存储桶」但是自带的域名无法访问,如果使用第三方域名还要做备案…

所以我又尝试了一下,创建了一个香港地区的存储桶。