How to Host a Static Site with Cloudflare Workers

Deploy a Hugo static site to Cloudflare Workers with Wrangler. Install the Workers CLI, configure wrangler.toml for Workers Sites, then publish to workers.dev or your own domain.

Cloudflare Workers provides a serverless execution environment that lets you run applications at the edge without configuring or maintaining infrastructure. Workers Sites lets you serve static assets (HTML, CSS, JS) from KV storage, which is ideal for static sites.

This guide uses Hugo to generate the static files. Hugo is a fast static site generator written in Go that turns Markdown (and other content) into static HTML. You can use any static generator; the steps are the same once you have a build output directory.

Prerequisites

  • Node.js and npm (for Wrangler).
  • A Hugo site (or any static site) with a build output directory (e.g. public/ for Hugo).
  • A Cloudflare account (free tier is enough).

Install the Workers CLI (Wrangler)

Workers Sites require Wrangler, the Cloudflare Workers CLI. Install it globally and keep it up to date:

1
npm install -g @cloudflare/wrangler

See the Wrangler installation docs for other install options (e.g. standalone binary).

Generate your static site

Build your Hugo site so the output directory (e.g. public/) is ready to upload:

1
hugo -D

Use whatever build command your static generator provides; the important part is having a folder of static files (e.g. public/).

Log in and create a Workers Site project

Log in to Cloudflare (this opens a browser to authenticate):

1
wrangler login

Create a new Workers Site project. This creates wrangler.toml and a workers-site directory:

1
wrangler init --site citizix

Replace citizix with your project name if you prefer.

Configure wrangler.toml

Edit wrangler.toml and set the bucket to your site’s build directory:

1
2
3
[site]
bucket = "./public"   # Your Hugo (or other) build output directory
entry-point = "workers-site"

Add your account_id to wrangler.toml. You can find it in the Cloudflare dashboard under Workers & Pages (or the Workers/Overview section) in the right sidebar—you may need to scroll down.

Preview locally

Preview your site before deploying:

1
wrangler preview --watch

This serves your static site locally so you can confirm everything looks correct.

Publish your site

Choose where to publish:

  1. workers.dev subdomain – Free *.workers.dev URL. Default: set workers_dev = true in wrangler.toml (or leave it unset).
  2. Custom domain – A domain you’ve added to Cloudflare. Add your zone_id and a route in wrangler.toml.

Custom domain example:

1
2
zone_id = "42ef..."
route = "example.com/*"

Find zone_id in the Cloudflare dashboard under your domain → Overview (right sidebar).

Then deploy:

1
wrangler deploy

Your static site will be live on your workers.dev URL or your custom domain.

Summary

You installed Wrangler, built a Hugo (or other) static site, configured wrangler.toml with your build directory and account (and optionally zone/route), and deployed with wrangler deploy. For more, see Cloudflare Workers Sites and Hugo’s documentation.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy