Make your site public
Put your site online with Cloudflare Workers, free for a small site.
On your computer the site only exists while hugo server runs. To make it public, build the pages and upload them. This takes about twenty minutes the first time and one command after that.
You need a free account at cloudflare.com and Node.js (node --version should print a number).
1. Add a Wrangler file#
Wrangler is Cloudflare’s upload tool. In your site folder, next to hugo.toml, create wrangler.jsonc:
{
"name": "my-site",
"compatibility_date": "2026-10-01",
"assets": { "directory": "public" }
}
Use lowercase letters, numbers and hyphens for name. It becomes part of your first address.
2. Build and upload#
npx wrangler login
hugo --minify
npx wrangler deploy
The first command opens a browser to let Wrangler use your account. The last one prints an address ending in .workers.dev. Open it: your site is online.
3. Use your own domain#
The domain must be added to your Cloudflare account first. If it is not, add it in the dashboard and change its name servers to the two Cloudflare shows you. That can take up to a day.
Then edit wrangler.jsonc:
{
"name": "my-site",
"compatibility_date": "2026-10-01",
"assets": { "directory": "public" },
"workers_dev": false,
"routes": [{ "pattern": "www.example.com", "custom_domain": true }]
}
Set baseURL in hugo.toml to the same address, with https:// and a closing slash, then run step 2 again. workers_dev: false turns the .workers.dev address off. The certificate is made for you and the address may take a few minutes to start.
Updating#
After any change, run the two commands again:
hugo --minify
npx wrangler deploy
To have Cloudflare do this on every push to GitHub, open Workers and Pages in the dashboard, create a Worker from your repository, and set the build command to hugo --minify and the deploy command to npx wrangler deploy. Add a variable HUGO_VERSION with your Hugo version, such as 0.168.0. Cloudflare changes these screens now and then, so follow what it shows if it differs.
If something looks wrong#
- Wrong links or pictures when shared.
baseURLdoes not match your real address. - Search does nothing. Add
home = ["HTML", "JSON"]under[outputs]inhugo.toml. - A script you added is blocked. The theme’s
_headersfile only lets pages run scripts from your own site. This protects visitors. To allow another one, add its address toscript-srcinstatic/_headers. Cloudflare Web Analytics is the usual case: addstatic.cloudflareinsights.comtoscript-srcandconnect-src, or turn it off.
Other hosts#
hugo --minify writes plain files into public/. Any static host works, including GitHub Pages and Netlify. Netlify reads _headers too. Elsewhere, set the same headers in the host’s settings.
To keep a site private, use Cloudflare Access (in the Zero Trust section of the dashboard). It needs no change to your files.