How to Deploy an Astro Site to Cloudflare Pages
A complete, step-by-step guide to deploying your Astro blog or site to Cloudflare Pages — from git push to a live URL on the global edge.
Cloudflare Pages gives you free, fast, global hosting for static sites — and Astro builds to exactly the kind of static output it loves. In this guide you’ll connect a repository and ship a live site in under ten minutes.
Before you start
You’ll need three things:
- An Astro project that builds locally (
npm run buildsucceeds). - A free Cloudflare account.
- Your code pushed to a GitHub or GitLab repository.
Step 1: Confirm your build command
Cloudflare needs to know how to build your site. For a standard Astro project the defaults are:
- Build command:
npm run build - Build output directory:
dist
If you use Pagefind for search, your build script should run it after Astro:
{
"scripts": {
"build": "astro build && pagefind --site dist"
}
}
Step 2: Create the Pages project
- In the Cloudflare dashboard, go to Workers & Pages → Create → Pages.
- Choose Connect to Git and authorize your repository.
- Select the repo and branch (usually
main).
Framework preset
Cloudflare detects Astro automatically and fills in the build command and output directory. Double-check they match Step 1, then click Save and Deploy.
Step 3: Watch the first build
Cloudflare clones your repo, installs dependencies, runs your build command, and uploads dist/ to its edge network. The first build takes a minute or two; subsequent builds are faster thanks to caching.
When it finishes you’ll get a URL like your-project.pages.dev. That’s your live site.
Step 4: Push to deploy
From now on, every push to your production branch triggers an automatic build and deploy. Pull requests get their own preview URLs, so you can review changes before they go live.
Step 5: Add a custom domain (optional)
In your Pages project, open Custom domains → Set up a custom domain, enter your domain, and follow the DNS prompts. If your domain already uses Cloudflare’s nameservers, the records are added for you and HTTPS is provisioned automatically.
Troubleshooting
- Build fails on Node version: set a
NODE_VERSIONenvironment variable (e.g.20) in your Pages settings. - 404s on routes with trailing slashes: make sure your
trailingSlashconfig inastro.config.mjsmatches how you link internally.
Frequently asked questions
Is Cloudflare Pages free? Yes — the free plan covers unlimited static requests and bandwidth, with generous build minutes. Most blogs and marketing sites never leave it.
Do I need Cloudflare Workers for a static Astro site? No. Pages serves static output directly. You only reach for Workers (or Astro’s SSR adapter) when you need server-side rendering or API routes.
How do I add a custom domain? In your Pages project, open Custom domains → Set up a custom domain. If the domain already uses Cloudflare’s nameservers, the DNS record and HTTPS certificate are provisioned for you automatically.
Can I preview pull requests before merging? Yes — every PR gets its own unique preview URL, so you can review changes in a real environment before they reach production.
That’s it — you now have a production site that redeploys on every push, served from hundreds of locations worldwide.
Tagged
Keep reading
Add Full-Text Search to Any Static Site with Pagefind
Static sites don't need a search server. Learn how Pagefind indexes your HTML at build time and adds fast, client-side full-text search for free.
Astro 6 Is Here: What's New for Content Sites
Astro 6 lands with a refined Content Layer, faster builds, and tighter defaults. Here's a quick tour of what matters most if you build blogs and content sites.
Cloudflare Keeps Pushing Compute to the Edge
Cloudflare's developer platform keeps growing — databases, object storage, and full-stack frameworks at the edge. What it means for how we ship web apps.