Deploying to Cloudflare Pages
This guide explains how to deploy your MkDocs documentation to Cloudflare Pages.
What is Cloudflare Pages?
Cloudflare Pages is a JAMstack platform for deploying static sites. It offers:
- Automatic builds from your Git repository
- Global CDN for fast content delivery
- Free SSL certificates
- Unlimited bandwidth and requests
- Preview deployments for pull requests
- Custom domains support
Prerequisites
Before deploying, you need:
- A Cloudflare account (free tier is sufficient)
- Your MkDocs project in a Git repository (GitHub, GitLab, or Bitbucket)
- The project configured with
mkdocs.yml
Deployment Steps
Step 1: Connect Your Repository
- Log in to the Cloudflare Dashboard
- Navigate to Pages in the sidebar
- Click Create a project
- Select Connect to Git
- Authorize Cloudflare to access your Git provider
- Select your repository
Step 2: Configure Build Settings
Configure the build settings for your MkDocs project:
Build configuration:
- Framework preset: None (or Custom)
- Build command:
mkdocs build - Build output directory:
site - Root directory:
/(or your project directory)
Environment variables:
You may need to set:
Step 3: Deploy
- Click Save and Deploy
- Cloudflare Pages will clone your repository and run the build
- Wait for the build to complete (usually 1-3 minutes)
- Your site will be available at
https://<project-name>.pages.dev
Build Command Details
The build process runs:
Make sure your requirements.txt includes:
Continuous Deployment
Once configured, Cloudflare Pages automatically:
- Rebuilds your site when you push to your default branch
- Creates preview deployments for pull requests
- Deploys changes globally within seconds
Custom Domains
To use a custom domain:
- Go to your project in Cloudflare Pages
- Navigate to Custom domains
- Click Set up a custom domain
- Follow the instructions to configure DNS
- Wait for SSL certificate provisioning (automatic)
Troubleshooting
Build Failures
If your build fails:
- Check the build logs in Cloudflare Pages dashboard
- Verify
requirements.txtcontains all dependencies - Ensure Python version is compatible (3.8+)
- Test the build locally:
mkdocs build
Common Issues
Issue: Module not found errors
Solution: Add missing dependencies to requirements.txt
Issue: Build timeout
Solution: Optimize your documentation or contact Cloudflare support
Issue: 404 errors after deployment
Solution: Check that site is set as the build output directory
Deployment Workflows
Production Workflow
graph LR
A[Push to main] --> B[Cloudflare triggers build]
B --> C[Install dependencies]
C --> D[Run mkdocs build]
D --> E[Deploy to production]
E --> F[Available globally]
Preview Workflow
graph LR
A[Open PR] --> B[Cloudflare creates preview]
B --> C[Build preview site]
C --> D[Preview URL available]
D --> E[Review changes]
Best Practices
- Test locally before pushing
- Use version pinning in requirements.txt
- Keep dependencies minimal for faster builds
- Monitor build times and optimize if needed
- Use preview deployments to test changes
Next Steps
Learn about configuration options for advanced customization.