Cloudflare Pages 自动化部署 Github 项目指南
![Cloudflare Pages 自动化部署 Github 项目指南](https://cdn.sanity.io/images/ntncowsx/production/e6ab6e3ab1cd7029723b988fc81fa10818c575e7-591x332.png?auto=format)
通过 Cloudflare Pages,你可以快速将 Github 上的前端静态项目免费部署到 Cloudflare 的全球 CDN 节点,享受极速加载体验。本指南将手把手教你如何借助 Cloudflare Pages 一键式部署 Github 项目。并使用自定义域名,让你的项目立即上线!
如果你之前没有了解过 Cloudflare,推荐通过我们的介绍进行简单了解。
🚀部署项目
进入 Cloudflare 面板,点击按图示进入 Workers 和 Pages 面板,点击“创建应用程序”。
![](https://cdn.sanity.io/images/ntncowsx/production/991957c8cfb225403f0f145fbbcb2a6ecad90cee-1286x804.png?w=1200&fit=max&auto=format)
选择“连接到 Git”。
![](https://cdn.sanity.io/images/ntncowsx/production/65cec9c2277fd4f068fb9b8aacef5e776c5f514d-1298x319.png?w=1200&fit=max&auto=format)
点击“添加账号”。
![](https://cdn.sanity.io/images/ntncowsx/production/1ba3205a0c8b6cdfef4e9ca1540162d0e56e93a0-882x632.png?w=1200&fit=max&auto=format)
通过 Github 账号授权🔑后进入 Github 个人设置界面。你可以选择授权所有项目给 Cloudflare,或者选择部分授权。我这里选择部分授权,然后选择你要授权的项目就可以。
![](https://cdn.sanity.io/images/ntncowsx/production/2dc4c3253f2c5dbc0647688a61685221b520b777-976x878.png?w=1200&fit=max&auto=format)
授权项目之后回到 Cloudflare 可以看到刚刚授权了的项目,选择一个你要部署的项目,点击“开始设置”。
![](https://cdn.sanity.io/images/ntncowsx/production/7d57253511057017e52dd72e602ca6d715328e53-718x515.png?w=1200&fit=max&auto=format)
部署静态页面,一般设置部署分支、构建命令、构建输出目录就可以。点击“保存并部署”。
![](https://cdn.sanity.io/images/ntncowsx/production/a12c27e41c2dda92ee93ba895b1312e95447298a-902x798.png?w=1200&fit=max&auto=format)
Cloudflare 开始部署,等待几分钟即可部署完成。
![](https://cdn.sanity.io/images/ntncowsx/production/364a4fb4e8e8124dce388fb0285beaa8d1940004-1020x670.png?w=1200&fit=max&auto=format)
部署完成后可看到 Cloudflare 生成给我们的域名,点击就可以访问了🎉。
![](https://cdn.sanity.io/images/ntncowsx/production/82359d9030286d7ef3c2612a64033bf55d7b28e1-1282x357.png?w=1200&fit=max&auto=format)
当你下次再推送代码到 Github 的时候会触发 Cloudflare Pages 自动部署,真的非常方便❤️。
🌐自定义域名
进入项目,点击“自定义域”。
![](https://cdn.sanity.io/images/ntncowsx/production/7027956efabb6c28cbb47e328862902cdd99a354-970x471.png?w=1200&fit=max&auto=format)
输入你的域名,点击“继续”➡️。
![](https://cdn.sanity.io/images/ntncowsx/production/6714b9b7138bf4b66494f57d672be0593581ae30-948x433.png?w=1200&fit=max&auto=format)
如果你的域名还没有接入 Cloudflare,会看到以下界面,点击“开始DNS转移”。然后按照《Cloudflare 简易接入指南》进行接入。
![](https://cdn.sanity.io/images/ntncowsx/production/a9704d6c79172f960517d95ced72350255563d33-940x529.png?w=1200&fit=max&auto=format)
Cloudflare 接入完成之后,再次进入配置 DNS 界面。界面就会变成下图这样,点击“激活域”。
![](https://cdn.sanity.io/images/ntncowsx/production/dd7b2fc5e4dbda9085bd12ddb5375e4fce1f3205-930x560.png?w=1200&fit=max&auto=format)
最后就是等待域名验证,Cloudflare 称 48 小时内会完成验证,实际上一般 1 小时⏱️内便可完成。
![](https://cdn.sanity.io/images/ntncowsx/production/3f6dc541cde1275c2ad8e3083720cb1068059d2a-731x245.png?w=1200&fit=max&auto=format)
域名验证成功后,你的项目就可以通过自定义域名正式上线了🎉!
喜欢站长