Tristan Grubbs
Technical Guide

Publish a Website with GitHub Pages + Cloudflare DNS/SSL

A complete walkthrough for hosting your site on GitHub Pages with a custom domain, Cloudflare DNS, and HTTPS.

This guide walks you through:

  • Buying a domain in Cloudflare
  • Hosting your site on GitHub Pages
  • Pointing your domain at GitHub using DNS records
  • Enabling HTTPS (SSL)

Prerequisites

  • A Cloudflare account
  • A GitHub account
  • A project/repo you want to host (or a new one)

1) Purchase a Domain in Cloudflare

  1. Log into Cloudflare
  2. Buy a domain (or transfer one in)
  3. Confirm the domain appears in your Account Home list

2) Create a New GitHub Repository

  1. Create a new repo on GitHub
  2. Put your website files in it (at minimum, an index.html in the repo root)

3) Enable GitHub Pages

In your GitHub repo, go to: Settings → Pages

Under Build and deployment, set:

  • Source: "Deploy from a branch"
  • Branch: main (and /root unless you're using /docs)

GitHub will generate a Pages URL for you (something like https://<user>.github.io/<repo>/) once it builds.

4) Add Your Custom Domain in GitHub Pages

In Settings → Pages, find Custom domain

Enter your domain:

  • If you want the root domain: example.com
  • If you want the www version: www.example.com

Save. This triggers a DNS verification check that will fail until you add DNS records in Cloudflare.

5) Open Your Domain in Cloudflare

  1. Go to Cloudflare Dashboard
  2. Click your new domain
  3. In the left sidebar, go to DNS → Records

6) Add DNS Records (A + CNAME)

A Records (for the apex/root domain)

Create 4 records with these settings:

Type Name IPv4 Address Proxy TTL
A @ 185.199.108.153 DNS only Auto
A @ 185.199.109.153 DNS only Auto
A @ 185.199.110.153 DNS only Auto
A @ 185.199.111.153 DNS only Auto

These are GitHub Pages' IPs for custom domains. All four are required for reliability.

CNAME Record (for www)

Type Name Target Proxy TTL
CNAME www <user>.github.io DNS only Auto

Common mistake: Putting only the repo name (like my-site) as the CNAME target. That is not a real hostname. Use <user>.github.io unless GitHub explicitly tells you otherwise.

7) Set Cloudflare SSL/TLS Mode

  1. In Cloudflare sidebar, go to SSL/TLS
  2. Find the encryption mode box and click Configure
  3. Select: Full (strict)

8) Finish HTTPS in GitHub Pages

  1. Go back to your repo: Settings → Pages
  2. Wait for the DNS check to show successful (this can take a bit)
  3. Enable Enforce HTTPS

9) Start Building Your Site

  1. Open your IDE
  2. Clone the repo (if you haven't):
    git clone <your-repo-url>
  3. Make changes, commit, push to main
  4. GitHub Pages redeploys automatically

Troubleshooting

DNS check won't pass:
Confirm Cloudflare records are set to DNS only, not proxied.

Site loads on www but not root (or vice versa):
Make sure you added the 4 A records for the root and the CNAME for www.

HTTPS not working:
Cloudflare mode must be Full (strict) and GitHub must have Enforce HTTPS enabled.

Wrong CNAME target:
Use <user>.github.io (not the repository name).

You're Done

Your domain should now serve your GitHub Pages site over HTTPS. Go make something nice, or at least something that loads.

← Back to Writing