How I Host My Next.js Websites on Cloudflare Pages for Free

Discover how to deploy Next.js applications on Cloudflare Pages with GitHub CI/CD - completely free hosting that actually works for real projects.

July 12, 2025
7 min read
nextjs-hosting
cloudflare-pages
free-hosting
github-cicd
static-deployment
developer-workflow
zero-cost-hosting


I've been hosting my Next.js projects on Cloudflare Pages for over a year now, and I'm genuinely surprised more developers don't know about this option. It's not just "free hosting" - it's actually good hosting that happens to be free. No catch, no hidden fees, just solid infrastructure.


The "Free Hosting" Problem


Let me be honest - I was skeptical about free hosting. I'd tried many hosting providers. They all had limitations that made them feel like "starter plans" rather than real hosting solutions.


But Cloudflare Pages is different. Here's what sold me:


The deployment process is stupid simple: Push to GitHub → Cloudflare automatically builds and deploys (Similar to Vercel and other platforms). No config files, no complex CI/CD setup.


The performance is impressive: We're talking about Cloudflare's global CDN. The same infrastructure that powers millions of websites.


The limits are generous: UNLIMITED BANDWIDTH. (At least for the time of writing this article.)


What "Forever Free" Actually Means


Here's my real hosting costs after running multiple Next.js projects on Cloudflare Pages:


ServiceMonthly CostAnnual Cost
Cloudflare Pages$0$0
Two domains (.com)~$2~$20
SSL Certificate$0$0
CDN & Bandwidth$0$0
Total~$2~$20

Compare that to traditional hosting where you're looking at $5-20/month minimum. Over a year, that's $60-240 vs ~$10 for just the domain.


Setup


Next.js Configuration for Static Export


The magic happens in your next.config.js. Here's the exact config I use:


javascript
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  trailingSlash: true,
  images: {
    unoptimized: true,
  },
  distDir: 'out',
};

export default nextConfig;

That's it. A few lines of config and you're ready for static deployment.


Why these settings matter:

output: 'export' - Tells Next.js to generate static files instead of server-side rendering
trailingSlash: true - Ensures proper routing on static hosts
images: { unoptimized: true } - Disables Next.js image optimization
distDir: 'out' - Specifies where the built files go (Cloudflare looks for this)

GitHub/GitLab Integration: The Real CI/CD Magic


Here's where it gets interesting. You don't need to configure any CI/CD pipelines. At all.


1.
Connect your GitHub/GitLab repo to Cloudflare Pages
2.
Push code to your main branch
3.
Cloudflare automatically builds and deploys

No GitHub Actions config, no complex workflows, no configuration files.


Cloudflare Pages CI/CD setup screen with GitHub integration

Cloudflare Pages CI/CD setup screen with GitHub integration


What Projects Work Best


I've deployed several types of projects on this setup:


Perfect for:

Personal portfolios and blogs
Marketing sites and landing pages
Documentation sites
Demo applications
Client project previews

Not ideal for:

Apps requiring server-side processing
Real-time applications
Complex user authentication
Database-heavy applications

But honestly? Most frontend projects fit the "perfect for" category.


Step-by-Step: My Actual Deployment Process


1. Setting Up the Project


Starting with a fresh Next.js project:


bash
npx create-next-app@latest my-project
cd my-project

Add the static export config to next.config.js:


javascript
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  trailingSlash: true,
  images: { unoptimized: true },
  distDir: 'out',
};

export default nextConfig;

2. Connecting to Cloudflare Pages


This is where it gets surprisingly simple:


1.
Push your code to GitHub (nothing special required)
2.
Go to Cloudflare Workers & Pages dashboard (in Compute (Workers) section → Workers & Pages)
3.
Click "Create" and select "Pages"
4.
Click "Get Started" on "Import an existing Git repository" and then select your repository
5.
Set the build configuration:
Framework preset: Next.js (Static HTML Export)
Build command: npx next build
Build output directory: out

Cloudflare Pages build configuration form

Cloudflare Pages build configuration form


6.
Click "Save and Deploy" (It will take a while to build)

That's it. No Docker files, no complex CI/CD configs, no environment variables to manage.


3. The Deployment Flow


Here's what happens every time you push code:


git push origin main
    ↓
GitHub webhook triggers Cloudflare
    ↓
Cloudflare clones your repo (freshest git commit)
    ↓
Runs npm install && npm run build
    ↓
Deploys to global CDN
    ↓
Your site is live in ~2 minutes

The best part? Preview deployments for every branch and pull request. Push a feature branch, get a unique URL to share with clients or teammates.


Real-World Performance and Gotchas


Performance That Surprised Me


I ran some tests comparing my Cloudflare Pages deployment to other hosting options:


My Static Site on Cloudflare:

Time to First Byte: 80-150ms globally
Lighthouse score: 95-100 consistently
First Contentful Paint: ~1.2s
Zero downtime in 12 months

Traditional hosting I tested:

TTFB: 500ms-2s (highly variable)
Lighthouse: 65-85 (server dependent)
Random downtime and slow response times

The consistency across different locations impressed me most. Poznań, Tokyo, New York, London - all perform similarly.


Common Gotchas and Solutions


Image optimization: Next.js image optimization doesn't work with static export. Use images: { unoptimized: true } and handle image optimization manually or use external services.


Dynamic imports: Be careful with dynamic imports. They work, but you need to ensure all dependencies are included in the build.


Environment variables: Build-time environment variables work fine, but remember there's no server-side runtime.


API routes: Don't work with static export. Use Cloudflare Workers or external APIs instead.


Custom Domains and SSL


Setting up a custom domain is straightforward:


1.
In Cloudflare Pages: Go to your project (Compute (Workers) section → Workers & Pages → Your project name) → Custom domains → Add domain
2.
In your domain registrar: Update nameservers to Cloudflare's
3.
SSL certificate: Automatically generated and managed by Cloudflare

The whole process takes about 5 minutes, and SSL is free and automatic.



Why This Actually Matters


The Problem with Traditional Hosting


I've been burned by traditional hosting before. Here's what usually happens:


1.
Start with shared hosting - $5-10/month, seems reasonable
2.
Performance issues - slow loading, occasional downtime
3.
Upgrade to VPS - $20-50/month, more complexity
4.
Manage server maintenance - updates, security patches, backups
5.
Still deal with performance issues during traffic spikes

And all of that only for a simple website with no backend logic.


With static hosting on Cloudflare Pages, I skip all of these problems. The site loads fast everywhere, never goes down, and costs nothing to run.


Real Projects I've Deployed


Here are some actual projects I'm running on this setup:


Personal portfolio + blog: hubertkasperek.com - My main portfolio site with integrated blog at hubertkasperek.com/blog. Pure static Next.js with MDX blog posts.


Micro SaaS project: BlitzyApp.com - A no-code platform for rapid idea validation. Uses Cloudflare Pages for the frontend and Cloudflare Workers for the backend API. This shows how you can extend the free tier with serverless functions.


School hackathon project: AssistlyApp - Educational app built during a hackathon. Also uses Cloudflare Pages + Workers for the backend functionality.


Client demos: Preview sites for client work - each gets its own repository and deployment


All of these run on the same free tier, perform well, and deploy automatically when I push code.


The "Catch" That Isn't Really a Catch


People always ask: "What's the catch?" The limitations are real but manageable:


No server-side processing: Use external APIs or Cloudflare Workers
No database: Use external services or file-based content
No real-time features: Use client-side solutions or external services

For 90% of developer portfolios and marketing sites, these limitations don't matter.


My Recommendation


When to Use This Setup


Perfect for:

Personal portfolios and blogs (without a CMS or with a headless CMS)
Project documentation
Marketing sites and landing pages (without a CMS or with a headless CMS)
Client project previews
Side project showcases (without a CMS or with a headless CMS)

Skip this for:

E-commerce sites with complex inventory
User-generated content platforms
Real-time applications
Sites requiring frequent database queries

Getting Started


If you want to try this, here's my suggestion:


1.
Start with a simple project - portfolio or documentation site
2.
Use the basic Next.js config I showed earlier
3.
Deploy to Cloudflare Pages with GitHub integration

The whole process can take about 30 minutes for a basic site, and you'll have a good sense of whether this approach works for your needs.


Summary


I've been running multiple projects on Cloudflare Pages for over a year now, and I'm genuinely impressed with the reliability and performance. The free tier is generous enough for real projects, the deployment process is seamless, and the global CDN performance is excellent.


Is it perfect? Not for every use case. But for developer portfolios, documentation sites, and frontend projects, it's hard to beat free hosting that works well.


The biggest benefit is not only the cost savings - it's also the simplicity. Push code, get deployment. No server management, no uptime monitoring, no surprise bills. Just focus on building your projects.


Want to try it yourself? Start with a simple Next.js project and see how it performs. You might be surprised by how well this "free" hosting works.


Thanks for reading!

I hope you found this article helpful, interesting, or useful! If you have questions, or just want to chat about web development, I'd love to hear from you.

Want to see what I'm building? Check out my projects or connect with me:

Published on July 12, 2025