Overview
Cloudflare Pages deploys static sites from a GitHub or GitLab repository, runs a build command on every push, and serves the output globally from Cloudflare’s CDN. This guide covers connecting a repository, setting environment variables, pointing a custom domain, and verifying the deployment. For the Quartz-specific path, see set-up-quartz-with-cloudflare-pages.
Prerequisites
- A Cloudflare account with Pages enabled.
- A GitHub repository containing the static site source. The repository must be accessible by your Cloudflare account.
- The site’s build command and output directory. Examples:
npm run buildanddistfor Vite;npx quartz buildandpublicfor Quartz. - A custom domain in Cloudflare DNS, if applicable.
Steps
1. Create a new Pages project
- Log in to the Cloudflare dashboard.
- Navigate to Workers and Pages > Pages > Create a project.
- Select Connect to Git and authorize Cloudflare to read your GitHub organization and repositories.
- Choose the repository and click Begin setup.
2. Configure build settings
Set the build configuration on the setup screen.
| Field | Example value |
|---|---|
| Framework preset | None (or select if applicable) |
| Build command | npm run build |
| Build output directory | dist |
| Root directory | / (unless monorepo) |
| Node.js version | 22 (set in environment variables as NODE_VERSION=22) |
For a Quartz 4 site:
Build command: npx quartz build
Build output directory: public
3. Set environment variables
Expand Environment variables during setup or add them later in Settings > Environment variables.
NODE_VERSION = 22
Add secrets (API keys, tokens) as encrypted environment variables. They are not exposed in build logs.
4. Deploy
Click Save and Deploy. Cloudflare Pages clones the repository, runs the build command, and publishes the output directory. The first deployment takes one to two minutes. Subsequent deployments are faster due to caching.
The project page shows the deployment URL: https://<project-name>.pages.dev.
5. Add a custom domain
- In the Pages project, go to Custom domains > Set up a custom domain.
- Enter the domain (
example.comorwww.example.com). - Cloudflare automatically creates a CNAME record if the domain is on the same Cloudflare account. For external DNS, add a CNAME pointing to
<project-name>.pages.dev. - SSL is provisioned automatically via Cloudflare’s certificate authority.
6. Configure branch deployments (optional)
Pages deploys every push to the production branch (usually main) as a production deployment, and every other branch as a preview deployment at a unique URL. Preview deployments share the same build settings but do not update the custom domain.
To skip preview builds for noisy branches, add a branch exclusion in Settings > Builds and deployments.
Verify it worked
# Check the live deployment
curl -I https://your-domain.com
# Expect: HTTP/2 200 and CF-Ray header confirming Cloudflare served it
# Check deployment status via Wrangler CLI
npx wrangler pages deployment list --project-name your-project-nameThe Cloudflare dashboard shows the latest deployment status, build time, and a link to the deployment log.
Common errors
- Build fails with “Node version not supported”: set
NODE_VERSION=22in environment variables. Cloudflare Pages defaults to Node 18. - Output directory not found: the build command succeeded but the output directory name does not match. Check the exact name (
dist,public,out,_site) in the build command docs. - Custom domain not serving: the CNAME record may not have propagated yet. Check with
dig your-domain.com CNAME. If on a different DNS provider, TTL may delay propagation up to 24 hours. - Environment variable not available during build: variables set in the Cloudflare dashboard are available as process environment variables during the build. Confirm the name matches exactly (case-sensitive).
- Pages quota exceeded: the free plan allows 500 deployments per month. For high-frequency deployments, consider Cloudflare Workers or upgrade the plan.