Cloudflare Pages allows you to deploy your site by either importing a Git repository from GitHub or GitLab, or by using a direct upload.
Deploy on Cloudflare Pages
After signing up and logging into Cloudflare Pages:
- Select Compute (Workers).
- On the Get Started page, choose Pages.
- Decide whether to Import an existing Git repository or Use direct upload..
Deploy from Git
- Under Deploy a site from your account, choose GitHub or GitLab and connect your account.
- After authentication, select your Alpha repository and click Begin Setup.
Set the following:
- Project name — This will define your site’s URL:
https://[project-name].pages.dev
- In your root
hugo.toml
, set:
baseURL = "https://[project-name].pages.dev"
- Commit and push the change to GitHub or GitLab.
- In your root
- Framework preset: Choose Hugo
- Build command:
- With search functionality:
hugo --gc --minify && npx pagefind --site "public"
- Without search:
hugo --gc --minify
- Environment variables (
+ Add variable
)- Variable name:
HUGO_VERSION
- Value:
0.147.7
Note: Use aHUGO_VERSION
greater than0.146.1
, ideally matching your local version.
- Variable name:
Once complete, click Save and Deploy.
When deployment finishes without errors, you can click Continue to Project.
Every consecutive push to your GitHub or GitLab repository will automatically trigger a deployment on Cloudflare Pages.
Deploy with Direct Upload
- From the Get started page on Compute (Workers), choose Use direct upload and then Get Started.
- Choose a project name (this becomes your site’s URL:
https://[project-name].pages.dev
) and click Create Project.- In your root
hugo.toml
setbaseURL = "https://[project-name].pages.dev"
and save the change. - Build your site locally:
- With Search:
hugo --gc --minify && npx pagefind --site "public"
- Without search:
Note: Search requires Node.js installed locally.hugo --gc --minify
- In your root
- In Cloudflare click select from computer, choose your local
public/
folder, and upload it. - Click Deploy Site and then Continue to Project.
For future updates (deployments):
- Build your site locally.
- Navigate to Workers & Pages →
[your project name]
. - Click Create deployment and re-upload the updated
public/
folder.
Custom Headers File (Optional)
Alpha includes a _headers
file preconfigured for a default Alpha installation, located at: /themes/alpha/static/_headers
.
This file allows you define security HTTP headers for your Cloudflare Pages deployment. Refer to the official official documentation for complete syntax, usage examples, and header options.
Warning
How to Use
- Copy the
_headers
file from/themes/alpha/static
to your site’sstatic/
directory. - Review and customize the rules to match your site’s security and performance needs.