Skip to content
COL0

How to publish an Astro (or static) site on Cloudflare

A static site is the simplest and cheapest way to be on the internet: it is generated once and served from a global network. Cloudflare does it with a domain and HTTPS included.

Written by Victor Barrera

What you need before starting

  • A project that generates static files (Astro, Vite, exported Next.js or plain HTML).
  • Your code on GitHub or GitLab and a Cloudflare account.
  • A domain (optional to start: you get a free test one).

The steps, in short

  1. Check the build locally: for example npm run build, and confirm it generates the output folder (dist in Astro).
  2. Connect the repository in Cloudflare and set the build command and output folder.
  3. Set the environment variables the build needs (public values only).
  4. Publish: every push to the main branch creates a new deployment, and other branches get a preview.
  5. Connect your domain from the dashboard; Cloudflare manages DNS and the HTTPS certificate.
  6. Adjust redirects and headers if you need them (for example, www to the main domain).
  7. Add a light backend with a function or Worker only if you need forms or an API.

Common mistakes

  • Setting the output folder wrong and publishing an empty page.
  • Using absolute paths from your computer for images or files.
  • Forgetting the trailing slash on URLs and ending up with duplicate links or 404s.
  • Putting private keys in variables that get embedded in the build.

How we help

We publish your site with automatic deploys, a domain, HTTPS and, if you need them, forms and functions in the same project.

Frequently asked questions

Can I publish a static site on Cloudflare for free?

Yes, there is a free plan suited to personal sites and small businesses. Check the current limits in Cloudflare's documentation before scaling.

What about environment variables on a static site?

Variables are read at build time and end up embedded in the output. Do not put secret keys there: anyone can see them in the published code.

Ready to publish your project?

Book your free 30-minute session and leave with a clear plan.

Book your free session