I have a gh-pages
branch in one of my http://github.com repos. The GitHub project pages works fine if I go to http://myuser.github.com/myrepo
I want to setup a custom domain (myexample.com) that will serve up this project pages. I want both myexample.com
and www.myexample.com
to serve up these project pages.
GitHub pages help says to make an A record and a CNAME record in your DNS. The A record makes sense, but I do not know what CNAME record to make in my DNS.
The gh-pages
docs say to make a CNAME
record for 'charlie.github.com' which is a user page repository. I do not have a user page repository - I only have a project repository and a gh-pages
branch that I want to use for myexample.com
and www.myexample.com
.
Do I need to make a user page repository just so I can use my project page for www.myexample.com and myexample.com?
I would just try it, but I want to make sure this will work as I already have www.myexample.com live and don't want to make a mistake.
I emailed GitHub support and their response was
You can't have both point to the same gh-pages as far as I know.
I find it hard to believe they would only support A records for project pages.
Has anyone successfully done this before?
You can customize the domain name of your GitHub Pages site. GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.
GitHub Pages is just the solution to that problem. It's free. You can host your website, including custom domain names(https://dhrumil.xyz), 404 error page, sub-domain (https://blog.dhrumil.xyz) and all over secure https.
On your site's repository, click the settings tab . Under custom domain, type your custom domain and save. GitHub will automatically create a commit with a CNAME file at the root of your repository. Visit the dashboard provided by your domain provider and add a CNAME record pointing to your subdomain.
The GitHub Pages repository URL is always https://{userid}.github.io/{reponame} The GitHub Pages URL is based on the GitHub repo URL, and takes the format https://{userid}.github.io/{reponame} . The moment you use it, GitHub Pages will generate a website based on the contents of your repo.
1/23/19 UPDATE:
Things have changed quite a bit (for the better) since my last answer. This updated answer will show you how to configure:
In the end, all requests to example.com
will be re-directed to https://www.example.com (or http:// if you choose NOT to use HTTPS). I always use www
as my final landing. Why(1,2), is for another discussion.
This answer is long but it is not complicated. I was verbose for clarity as the GitHub docs on this topic are not clear or linear.
GitHub Pages
section. You have two options: master branch
will treat /README.md
as your web index.html
. Choosing master branch /docs folder
will treat /docs/README.md
as your web index.html
.Your site is ready to be published at
Enter your custom domain name here and hit save
:
This is a subtle, but important step.
example.com
, then www.example.com
will redirect to example.com
www.example.com
, then example.com
will redirect to www.example.com
.As mentioned before, I recommend always landing at www
so I entered www.example.com
as pictured above.
In your DNS provider's web console, create four A
records and one CNAME
.
A
Records for @
(aka root apex):Some DNS providers will have you specify @
, others (like AWS Route 53) you will leave the sub-domain blank to indicate @
. In either case, these are the A
records to create:
185.199.108.153 185.199.109.153 185.199.110.153 185.199.111.153
Check the Github docs to confirm these are the most up-to-date IPs.
CNAME
record to point www.example.com to YOUR-GITHUB-USERNAME.github.io
.This is the most confusing part.
Note the YOUR-GITHUB-USERNAME
NOT the GitHub repo name! The value of YOUR-GITHUB-USERNAME
is determined by this chart.
For a User pages site (most likely what you are), CNAME
entry will be username.github.io
, ex:
For a Organization pages site, CNAME
entry will be orgname.github.io
, ex:
Confirm your A
records by running dig +noall +answer example.com
. It should return the four 185.x.x.x
IP addresses you entered.
Confirm your CNAME
record by running dig www.example.com +nostats +nocomments +nocmd
. It should return a CNAME YOUR-GITHUB-USERNAME.github.io
It may take an hour or so for these DNS entries to resolve/propagate. Once they do, open up your browser to http://example.com
and it should re-direct to http://www.example.com
After you have the custom domain working, go back to the repo settings. If you already have the settings page open, hard refresh the page.
If there is a message under the Enforce HTTPS
checkbox, stating that it is still processing you will need to wait. You may also need to hit the save
button in the Custom domain
section to kick off the Enforce HTTPS
processing.
Once processing is completed, it should look like this:
Just click on the Enforce HTTPS
checkbox, and point your browser to https://example.com
. It should re-direct and open https://www.example.com
GitHub will automatically keep your HTTPS cert up-to-date AND should handle the apex to www
redirect over HTTPS.
Hope this helps!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With