Deploying static websites has evolved significantly from the days of configuring Apache virtual hosts, managing SFTP uploads, or configuring raw S3 buckets with manual CloudFront distributions. Modern edge platforms now combine global Content Delivery Networks (CDNs), continuous integration pipelines, automated TLS provisioning, and edge compute into unified developer platforms.

Among current offerings, Cloudflare Pages has emerged as one of the most reliable and cost-effective solutions for static sites and Jamstack applications. Powered by Cloudflare’s Anycast network spanning over 300 cities across more than 100 countries, Pages delivers sub-millisecond edge routing, unlimited bandwidth on standard tiers, and instant cache invalidation.

In this practical guide, we cover everything required to deploy, configure, and maintain a production-ready static site on Cloudflare Pages, covering both Git-based continuous integration and direct CLI deployments via Wrangler.


Why Choose Cloudflare Pages?

Before diving into configuration, it is useful to understand what differentiates Cloudflare Pages from traditional web servers:

  1. Global Anycast Edge Network: Assets are cached and served from the physical data center closest to the requesting visitor, dramatically reducing Time to First Byte (TTFB).
  2. Zero Maintenance Infrastructure: There are no virtual machines to patch, no Nginx configs to reload, and no server daemon crashes to monitor.
  3. Automated SSL/TLS: Cloudflare provisions and automatically renews SSL certificates via Let’s Encrypt and Google Trust Services with zero configuration.
  4. Isolated Preview Deployments: Every pull request or non-production branch automatically generates a unique preview URL (e.g., https://commit-hash.project-name.pages.dev), enabling team reviews before merging to production.
  5. Native Edge Logic: When your application requires server-side logic, you can seamlessly add Cloudflare Workers functions inside a /functions folder without rewriting your application architecture.

Architecture Overview

+---------------------------------------------------------------------------------+
|                               Deployment Workflow                               |
+---------------------------------------------------------------------------------+
|                                                                                 |
|   Developer              GitHub / GitLab                     Cloudflare Pages   |
|   +-----------+          +---------------+                   +---------------+  |
|   | git push  | -------> | Main Branch   | --- Webhook ----> | CI Runner     |  |
|   +-----------+          +---------------+                   +---------------+  |
|                                                                      |          |
|                                                              Execute Build      |
|                                                              (hugo / npm build) |
|                                                                      |          |
|                                                                      v          |
|                                                              +---------------+  |
|                                                              | Output Dir    |  |
|                                                              | (public/dist) |  |
|                                                              +---------------+  |
|                                                                      |          |
|                                                              Distribute to Edge |
|                                                                      v          |
|                                                           +-------------------+ |
|                                                           | 300+ Edge Nodes   | |
|                                                           +-------------------+ |
+---------------------------------------------------------------------------------+

The most common and maintainable deployment method connects your Git repository directly to Cloudflare Pages. Whenever you push commits to your repository, Cloudflare pulls the code, executes the build command in an isolated container, and publishes the output directory.

Step 1: Create a Cloudflare Account and Connect Repository

  1. Log in to the Cloudflare Dashboard.
  2. In the left navigation sidebar, select Workers & Pages.
  3. Click Create Application, then select the Pages tab.
  4. Click Connect to Git.
  5. Authorize Cloudflare to access your GitHub or GitLab account. You can grant access to all repositories or restrict permissions to specific project repositories.

Step 2: Configure Build and Environment Settings

Once you select your target repository, Cloudflare presents the build configuration screen:

  • Project name: Choose an identifier (this forms your default subdomain: <project-name>.pages.dev).
  • Production branch: Typically main or master. Any commit pushed to this branch triggers a live production deployment.
  • Framework preset: Cloudflare provides pre-configured presets for popular static tools.

Below are standard presets for common static frameworks:

Hugo

  • Framework preset: Hugo
  • Build command: hugo --gc --minify
  • Build output directory: public
  • Environment variables:
    • HUGO_VERSION: 0.136.0 (specify the version matching your local environment)

Astro

  • Framework preset: Astro
  • Build command: npm run build
  • Build output directory: dist
  • Environment variables:
    • NODE_VERSION: 20.18.0

Next.js (Static HTML Export)

  • Framework preset: Next.js (Static HTML Export)
  • Build command: npm run build
  • Build output directory: out
  • Environment variables:
    • NODE_VERSION: 20.18.0

Vite (React, Vue, or Vanilla JS)

  • Framework preset: Vite
  • Build command: npm run build
  • Build output directory: dist

Step 3: Handling Git Submodules (Critical for Hugo Themes)

If you are using Hugo themes installed via Git submodules (such as PaperMod), Cloudflare Pages must clone submodules recursively during the build process.

Ensure your .gitmodules file in the root of your project contains correct relative or public HTTPS URLs:

[submodule "themes/PaperMod"]
	path = themes/PaperMod
	url = https://github.com/adityatelange/hugo-PaperMod.git

Cloudflare Pages automatically initializes and updates submodules by default as long as the submodules are public or accessible with the granted repository credentials.


Method 2: Deploying via Wrangler CLI

If you prefer building assets within your own continuous integration pipeline (such as GitHub Actions) or deploying directly from a terminal without connecting repository write access to Cloudflare, use the Wrangler CLI.

Step 1: Install Wrangler

Install Wrangler globally or locally within your project:

# Global installation
npm install -g wrangler

# Or verify with npx
npx wrangler --version

Step 2: Authenticate Wrangler

Run the login command to authenticate your local shell with Cloudflare:

npx wrangler login

This launches a browser window where you grant API authorization. Once authorized, Wrangler stores credentials in ~/.wrangler/config/default.toml.

For CI/CD runners, you authenticate using environment variables instead of interactive login:

  • CLOUDFLARE_API_TOKEN: Create an API token in the Cloudflare Dashboard under My Profile > API Tokens with permissions: Cloudflare Pages: Edit.
  • CLOUDFLARE_ACCOUNT_ID: Located on the overview page of your Cloudflare Dashboard.

Step 3: Build and Deploy

Execute your local build step, then publish the output directory:

# Example for Hugo
hugo --gc --minify

# Deploy the output directory to Cloudflare Pages
npx wrangler pages deploy ./public --project-name=my-company-blog --branch=main

When deploying from a feature branch:

# Preview deployment
npx wrangler pages deploy ./public --project-name=my-company-blog --branch=feature-new-header

Wrangler will package the assets, upload only modified files using SHA-256 content hashing, and return both the unique deployment URL and the project URL.


Advanced Cloudflare Pages Configurations

To take full control of caching, security headers, and routing rules, Cloudflare Pages supports special configuration files placed directly inside your build output directory.

1. Custom HTTP Headers (_headers)

Create a file named _headers in your static assets directory (for Hugo, place it in static/_headers; for Vite/Astro, place it in public/_headers). When built, this file lands in the root of your published output.

Here is a hardened security and caching configuration:

/*
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: document-domain=(), geolocation=(), microphone=(), camera=()
  Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https:; script-src 'self'; connect-src 'self';

# Cache immutable assets (CSS, JS, fonts, images with content hashes)
/assets/*
  Cache-Control: public, max-age=31536000, immutable

# HTML pages should always revalidate to show updates immediately
/*.html
  Cache-Control: public, max-age=0, must-revalidate

/
  Cache-Control: public, max-age=0, must-revalidate

2. Custom Redirects and Rewrites (_redirects)

To handle legacy URL migrations, redirects, or SPA client-side routing, add a _redirects file to your output directory:

# 301 Permanent Redirects for restructured content
/old-post                     /posts/new-post               301
/about-us                     /about                        301

# Subpath wildcard redirect
/docs/v1/*                    /docs/v2/:splat               301

# Single Page Application (SPA) fallback rewrite (if using client-side routing)
# /*                          /index.html                   200

Troubleshooting Common Deployment Failures

Issue Root Cause Solution
hugo: command not found Default environment missing Hugo or using outdated runtime version. Define HUGO_VERSION environment variable in Pages settings (e.g. 0.136.0).
Theme styles missing / blank page Submodules failed to clone or baseURL is misconfigured. Verify .gitmodules points to public HTTPS URL; ensure baseURL is set to / or your custom domain.
Error: Node version not supported Default Node version in build container is outdated (Node 12/16). Set environment variable NODE_VERSION: 20 in project build settings.
Old content showing after deployment Browser cache holding onto HTML pages. Ensure _headers specifies Cache-Control: public, max-age=0, must-revalidate on HTML files.
404 Not Found on direct link refresh SPA router without fallback rule. Add /* /index.html 200 to _redirects.

Production Launch Checklist

Before sharing your new site with users, verify the following configuration points:

  • Repository connected with automated branch tracking.
  • Production branch builds without warnings or deprecated flags.
  • _headers file deployed and verified via curl -I https://<your-project>.pages.dev.
  • Submodules correctly updated on every commit.
  • Custom domain connected and DNS CNAME record verified.
  • SSL certificate active and HSTS header returning max-age=31536000.
  • Preview deployments functioning on Pull Requests.

Cloudflare Pages provides a rock-solid, zero-maintenance foundation for modern web engineering. By deploying static assets directly to the edge, your application achieves stellar performance, bulletproof security, and predictable operating costs.