Configure a GitHub Repository to Use A Cloudflare DNS Custom Subdomain
Have you ever wanted to set up a custom subdomain for your GitHub repository? By using Cloudflare DNS, you can easily achieve this. In this guide, we will walk you through the steps to configure your GitHub repository to use a Cloudflare DNS custom subdomain. Let’s get started!
Adding a Subdomain to Cloudflare
- Login to Cloudflare at cloudflare.com.
- In the upper left of your screen, click on your domain name where you want the redirect to take place.
- Click the DNS tab in the menu on the left.
- Under the records section, click Add Record.
- Set the Type to CNAME.
- Enter the Name of your subdomain (e.g., “blog”).
- Set the Target to “githubusername.github.io” (replace “githubusername” with your actual GitHub username).
- Leave the TTL as automatic and enable Proxy status.
- Click the Save button.
Congratulations!!! You have now added your subdomain to Cloudflare.
Setting up GitHub Pages for Your Custom Subdomain
- Login to GitHub at github.com.
- Click on your account/organization and navigate to the repository you want to configure the subdomain for (githubusername.github.io).
- While inside your repository’s code section, click Settings.
- Scroll down to the Pages section and select the main branch or the branch you are using for this repository.
- In the Custom domain field, enter your subdomain (e.g., “blog.yourdomain.com”).
- Click the Save button.
Great job! You have successfully set up GitHub Pages for your custom subdomain.
Updating the Repository URL
- Edit the
_config.yml
file in your repository. - Change the URL from
url: 'https://githubusername.github.io'
tourl: 'https://yoursubdomain.yourdomain.com'
(replace “yoursubdomain” and “yourdomain” with your actual subdomain and domain).
And you’re done! You have now updated the URL that your repository is pointing to.
Summary:
By following these steps, you have configured a custom subdomain for your GitHub repository using Cloudflare DNS. Your subdomain, such as “blog.yourdomain.com,” now points to your GitHub Pages site. You can access your site using either the custom subdomain or the original GitHub URL, and both will display identical information.
Now you can personalize your GitHub repository and make it even more accessible to your audience. Enjoy sharing your projects with the world!!
Note: The instructions in this guide assume you already have a registered domain and have access to manage its DNS settings on Cloudflare.