

























博客逐步搭建完善,更新了日常使用的 App、 硬件页面。博客样式标题采用了" 得意黑“开源字体。把二级域名改成一级,过程中发现 Cloudflare Pages 如果要绑定一级,须把域名的 DNS 服务器解析过去。解析之后,自己的 nas 访问变得不稳定,时不时的打不开,来来回回折腾了好几次,无解,只好改回去。 vercel 可以绑定一级,尝试之后,访问速度太慢,放弃。开始了解国内的云服务,学习到了对象储存、CDN,经过一番对比尝试,最终选择腾讯云的 COS 对象存储配合内容分发网络 CDN 搭建(主要它的 cosbrowser 界面是经过设计的 ᵔ◡ᵔ;客服也很负责,咨询问题会电话打过来详细教你如何操作)。
在了解部署过程中发现 Cyrus’s Blog 写的”
自动构建 Hugo 博客部署至腾讯云对象存储 COS 并刷新 CDN“教程,一番折腾,完美。感谢作者。
备份记录下过程: (详细的注释可查看 Cyrus’s Blog)
name: Build and deploy
# 自动触发构建
on:
push:
branches:
- main
# 构建hugo及生产静态页面
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
extended: true
- name: Build
run: hugo --minify
# 上传到腾讯COS存储桶
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Setup coscmd and sdk
run: sudo pip install coscmd
- name: Configure coscmd
env:
SECRET_ID: ${{ secrets.SecretId }}
SECRET_KEY: ${{ secrets.SecretKey }}
BUCKET: ${{ secrets.Bucket }}
REGION: ${{ secrets.Region }}
run: coscmd config -a $SECRET_ID -s $SECRET_KEY -b $BUCKET -r $REGION
- name: Upload to COS
run: coscmd upload -rfs --delete public/ /
# 刷新腾讯CDN缓存目录
- name: Flush CDN
env:
SECRET_ID: ${{ secrets.SecretId }}
SECRET_KEY: ${{ secrets.SecretKey }}
run: |
pip install --upgrade tencentcloud-sdk-python
python flush-dns.py -i $SECRET_ID -k $SECRET_KEY
import json
import argparse
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import (
TencentCloudSDKException,
)
from tencentcloud.cdn.v20180606 import cdn_client, models
# 传入参数
parser = argparse.ArgumentParser(description='-i <secretId> -k <secretKey>')
parser.add_argument('-i', '--secretid', type=str, required=True, help='secretId')
parser.add_argument('-k', '--secretkey', type=str, required=True, help='secretKey')
args = parser.parse_args()
try:
cred = credential.Credential(args.secretid,args.secretkey)
httpProfile = HttpProfile()
httpProfile.endpoint = "cdn.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = cdn_client.CdnClient(cred, "", clientProfile)
req = models.PurgePathCacheRequest()
params = {"Paths": ["https://koobai.com/", "https://www.koobai.com/"], "FlushType": "flush"}
req.from_json_string(json.dumps(params))
resp = client.PurgePathCache(req)
print(resp.to_json_string())
except TencentCloudSDKException as err:
print(err)
自此部署完毕,当有新文件上传到 main 分支,就会自动触发(hugo 生成静态文件——上传到 COS——刷新 CDN 缓存)。
COS、CDN 费用(包含存储+CDN 回源流量+CDN 流量+HTTPS 请求等),个人站没什么流量,应该很低,跑一段时间看看。另外腾讯云也提供了六个月一部分免费试用~~
因为博客源文件在 Github 里,可以利用 vercel 平台读取仓库也自动构建一个。如果使用的是阿里云域名 DNS 服务器,可以在解析请求来源选择"境外",“记录值"填写 vercel 平台绑定域名时所提供的。
这样国内网络访问的时候走腾讯 CDN,国外访问的时候走 vercel 平台所提供的节点。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。