Linking your domain to GitHub Pages can be done efficiently with Cloudflare as your DNS provider. Here is a step-by-step guide to help you set up your domain to work with GitHub Pages.
Prerequisites
-
A GitHub Repository: Ensure you have a GitHub repository with GitHub Pages enabled.
-
Domain Name: You need a domain registered with us, click here to register your domain now.
-
Cloudflare Account: Create a free Cloudflare account if you don’t already have one.
Step 1: Add Your Domain to Cloudflare
-
Log in to Cloudflare:
-
Go to Cloudflare and log in to your account.
-
-
Add Your Site:
-
Click on Add a Site and enter your domain name.
-
-
Choose a Plan:
-
Select the free plan or a paid plan depending on your needs and click Continue.
-
-
Verify DNS Records:
-
Cloudflare will scan your existing DNS records. Review them and ensure they match the current records from your domain registrar.
-
-
Update Nameservers:
-
Cloudflare will provide you with nameservers. Update your nameservers on your dashboard to the ones provided by Cloudflare. This step may take a few hours to propagate.
-
Step 2: Configure DNS Records in Cloudflare
-
Access the DNS Settings:
-
In Cloudflare, navigate to the DNS section of your domain.
-
-
Add an A Record:
-
Click on Add Record.
-
Select Type: A
-
Name: Enter
@
for the root domain or the subdomain you want to use. -
IPv4 Address: Use
185.199.108.153
,185.199.109.153
,185.199.110.153
, and185.199.111.153
(GitHub Pages IPs). Add four A records, one for each IP address. -
Proxy Status: Set to DNS only (gray cloud).
-
-
Add a CNAME Record (for subdomains):
-
If you’re pointing a subdomain to GitHub Pages (e.g.,
www.example.com
):-
Select Type: CNAME
-
Name:
www
(or your subdomain prefix). -
Target:
your-username.github.io
. -
Proxy Status: Set to DNS only (gray cloud).
-
-
Step 3: Configure GitHub Pages
-
Open Your Repository:
-
Go to your GitHub repository.
-
-
Enable GitHub Pages:
-
Navigate to Settings > Pages.
-
Under “Source,” select the branch and folder you want to use (usually
main
and/root
for most setups).
-
-
Set Your Custom Domain:
-
Under the Custom Domain section, enter your domain name (e.g.,
example.com
). -
Click Save.
-
-
Verify GitHub Pages Certificate:
-
GitHub Pages will issue an SSL certificate. Ensure that “Enforce HTTPS” is enabled once the certificate is ready.
-
Step 4: Test Your Setup
-
DNS Propagation:
-
It may take a few hours for DNS changes to propagate globally.
-
-
Verify Domain Connection:
-
Open your browser and visit your domain (e.g.,
https://example.com
) to ensure it’s correctly pointing to your GitHub Pages site.
-
-
Troubleshooting:
-
Use tools like WhatsMyDNS to check DNS propagation.
-
Ensure Cloudflare’s records are correct and that GitHub Pages is properly configured.
-
Additional Tips
-
Redirect www to root domain:
-
In Cloudflare, create a CNAME record pointing
www
to your root domain if you want bothwww.example.com
andexample.com
to work.
-
-
DNS Caching:
-
Clear your browser’s cache or flush your local DNS cache if changes don’t seem to take effect immediately.
-
By following these steps, you’ll successfully link your domain to GitHub Pages using Cloudflare. Enjoy your new website!