前言

Cloudflare Pages 是一个静态网站托管服务,功能和 Github Pages 差不多,

可以存放静态网页,还可以直接部署前端项目。如果你的网站只是静态博客或帮助文档的话,可以完全不需要购买服务器。

Cloudflare 是全球最大的几个 CDN 服务商之一,速度应该会比 Github Pages 好一些,而且 Cloudflare Pages 一个账户可以创建多个网站

开始部署

在此之前,我们需要在 Github 创建一个仓库

并且将你的 Hugo 网站目录一整个上传上去(不用上传 Hugo二进制文件)

然后也可以使用 Github Desktop 克隆下来方便后期修改和 Push

现在可以开始部署 Cloudflare Pages了

先注册且登录 Cloudflare

https://dash.cloudflare.com/

然后找到 Workers 和 Pages,点击创建应用程序,并且开始创建 Pages

createpages

紧接着我们选择 连接到 Git
connectgit

之后我们再选择好 Github 账户和相对于的 Github 仓库
choosegit

如果未显示您的存储库,请在 GitHub 上为 Cloudflare Pages 应用配置存储库访问权限

https://github.com/settings/installations/38244147
githubcloudflare
上面的两个选项分别是:

All repositories Onlyselect repositories

意思是,授权 Cloudflare 访问所有的仓库和选择单一一个仓库授权的意思

选择完毕后开始按照如图设置填入:

其中变量设置可选,可以在构建失败时或者对不上你的网站主题版本时可以添加

如下

HUGO_VERSION        0.117.0

peizhigit

此时我们就可以下一保存并部署了!

这是我第一次部署时的日志:

2023-08-28T08:25:04.20513Z Cloning repository...
2023-08-28T08:25:05.045302Z From https://github.com/whohhnb/hugo_blog
2023-08-28T08:25:05.046014Z  * branch            3e88fb9c76c874ec9d721477f8de57d06ff51e8e -> FETCH_HEAD
2023-08-28T08:25:05.046203Z 
2023-08-28T08:25:05.119143Z HEAD is now at 3e88fb9 awa
2023-08-28T08:25:05.119801Z 
2023-08-28T08:25:05.22682Z 
2023-08-28T08:25:05.260299Z Success: Finished cloning repository files
2023-08-28T08:25:06.392499Z Detected the following tools from environment: hugo@extended_0.117.0
2023-08-28T08:25:06.393457Z Installing hugo extended_0.117.0
2023-08-28T08:25:06.559641Z * Downloading hugo release extended_0.117.0...
2023-08-28T08:25:08.178225Z hugo extended_0.117.0 installation was successful!
2023-08-28T08:25:08.532436Z Executing user command: hugo
2023-08-28T08:25:08.85654Z Start building sites … 
2023-08-28T08:25:08.856927Z hugo v0.117.0-b2f0696cad918fb61420a6aff173eb36662b406e+extended linux/amd64 BuildDate=2023-08-07T12:49:48Z VendorInfo=gohugoio
2023-08-28T08:25:08.857136Z 
2023-08-28T08:25:08.862031Z WARN  found no layout file for "html" for kind "home": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
2023-08-28T08:25:08.862371Z WARN  found no layout file for "html" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
2023-08-28T08:25:08.864898Z 
2023-08-28T08:25:08.865146Z                    | EN  
2023-08-28T08:25:08.865314Z -------------------+-----
2023-08-28T08:25:08.865457Z   Pages            |  3  
2023-08-28T08:25:08.865587Z   Paginator pages  |  0  
2023-08-28T08:25:08.865741Z   Non-page files   |  0  
2023-08-28T08:25:08.865872Z   Static files     |  0  
2023-08-28T08:25:08.865997Z   Processed images |  0  
2023-08-28T08:25:08.866151Z   Aliases          |  0  
2023-08-28T08:25:08.866293Z   Sitemaps         |  1  
2023-08-28T08:25:08.866421Z   Cleaned          |  0  
2023-08-28T08:25:08.866543Z 
2023-08-28T08:25:08.866702Z Total in 11 ms
2023-08-28T08:25:08.877522Z Finished
2023-08-28T08:25:08.878207Z Note: No functions dir at /functions found. Skipping.
2023-08-28T08:25:08.878403Z Validating asset output directory
2023-08-28T08:25:09.569068Z Deploying your site to Cloudflare's global network...
2023-08-28T08:25:12.028424Z Uploading... (0/4)
2023-08-28T08:25:12.562349Z Uploading... (1/4)
2023-08-28T08:25:12.566719Z Uploading... (3/4)
2023-08-28T08:25:12.617692Z Uploading... (4/4)
2023-08-28T08:25:12.618171Z ✨ Success! Uploaded 4 files (1.02 sec)
2023-08-28T08:25:12.618392Z 
2023-08-28T08:25:12.818423Z ✨ Upload complete!
2023-08-28T08:25:14.791899Z Success: Assets published!
2023-08-28T08:25:15.443583Z Success: Your site was deployed!

如果差不多的话基本上就可以按照他给出的免费域名访问了,建议绑定域名访问

如果你第一次想部署 Hugo 你可以按照我的文章去参考

Debian搭建hugo系统