GitHub Pages supports custom domains. If your domain is managed in AWS Route 53, you can point the root domain, for example opeshm.net, directly to your GitHub Pages site instead of using only a subdomain such as blog.opeshm.net.
The setup happens in two places: the DNS records in Route 53 and the GitHub Pages settings in the repository.
Before you start#
You need:
- A domain managed in Route 53, for example
opeshm.net. - A repository with GitHub Pages enabled.
- Access to
Settings > Pagesin the repository.
The examples use opeshm.net as the root domain. Replace it with your own domain.
1. Configure the A records in Route 53#
For a root domain, also called an apex domain, you do not use a CNAME. GitHub Pages publishes fixed IP addresses, and the root domain must point to them with A records.
In AWS:
- Open the AWS console.
- Go to
Route 53. - Open
Hosted zones. - Select the hosted zone for the domain, for example
opeshm.net. - Create a record for the root domain by leaving
Record nameempty. - Use type
A. - Add these values:
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153Depending on the Route 53 interface, you can add them as one A record with multiple values or as equivalent records.
2. Configure the www subdomain#
It is usually worth making www.yourdomain.com work too.
In Route 53, create this record:
Record name: www
Type: CNAME
Value: your-user.github.ioReplace your-user.github.io with the GitHub Pages domain for your account or organization.
With this, www.opeshm.net will point to the same site as the root domain.
3. Configure the domain in GitHub Pages#
After creating the DNS records, GitHub needs to know that it should accept requests for the domain.
In GitHub:
- Open the repository.
- Go to
Settings. - Open
Pages. - In
Custom domain, enter the root domain, for exampleopeshm.net. - Save the change.
GitHub will check the DNS records. Validation can take from a few minutes to a few hours, depending on DNS propagation.
If the site is published with a GitHub Actions workflow, it is also useful to keep the custom domain as a CNAME file in the generated site. In Hugo, a simple way is to create static/CNAME with this content:
opeshm.netHugo will copy it to public/CNAME during the build.
4. Enable HTTPS#
When GitHub validates the domain, go back to Settings > Pages and enable Enforce HTTPS.
GitHub will automatically issue a free TLS certificate for the domain. The option can take a few minutes to become available while the certificate is generated.
5. Decide what to do with the old subdomain#
If you previously used blog.opeshm.net, you have two options:
- Keep it if you still want it to resolve somewhere.
- Delete it from Route 53 if you no longer want to use it.
Keep in mind that a GitHub Pages repository only has one primary custom domain configured in Settings > Pages. If you want to keep the subdomain, you will usually use it as a redirect or for a separate site.
Final DNS setup#
A typical setup looks like this:
| Name | Type | Value |
|---|---|---|
opeshm.net | A | 185.199.108.153, 185.199.109.153, 185.199.110.153, 185.199.111.153 |
www.opeshm.net | CNAME | your-user.github.io |
blog.opeshm.net | CNAME | Only if you still need it |
Check the result#
After DNS propagation finishes, check that the domain resolves correctly:
dig opeshm.net A
dig www.opeshm.net CNAMEThen open the site in the browser:
https://opeshm.netIf GitHub Pages serves the site and Enforce HTTPS is enabled, the migration from the subdomain to the root domain is complete.