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?
The documentation is a little confusing when it comes to project pages, as opposed to user pages. It feels like you should have to do more, but actually the process is very easy.
It involves:
Your content will be served from a URL of the form http://nicholasjohnson.com.
Visiting http://www.nicholasjohnson.com will return a 301 redirect to the naked domain.
The path will be respected by the redirect, so traffic to http://www.nicholasjohnson.com/angular will be redirected to http://nicholasjohnson.com/angular.
You can have one project page per repository, so if your repos are open you can have as many as you like.
Here's the process:
For the A records, point @ to the following ip addresses:
@: 185.199.108.153
@: 185.199.109.153
@: 185.199.110.153
@: 185.199.111.153
These are the static Github IP addresses from which your content will be served.
For the CNAME record, point www to yourusername.github.io. Note the trailing full stop. Note also, this is the username, not the project name. You don't need to specify the project name yet. Github will use the CNAME file to determine which project to serve content from.
e.g.
www: forwardadvance.github.io.
The purpose of the CNAME is to redirect all www subdomain traffic to a GitHub page which will 301 redirect to the naked domain.
Here's a screenshot of the configuration I use for my own site http://nicholasjohnson.com:
Add a file called CNAME to your project root in the gh-pages branch. This should contain the domain you want to serve. Make sure you commit and push.
e.g.
nicholasjohnson.com
This file tells GitHub to use this repo to handle traffic to this domain.
Now wait 5 minutes, your project page should now be live.
I'd like to share my steps which is a bit different to what offered by rynop and superluminary.
A
Record is exactly the same but CNAME
for www
I would prefer to redirect it to my blank domain (non-www
)This configuration is referring to guidance of preferred domain. The domain setting of www
to non www
or vise versa can be different on each of the domain providers. Since my domain is under GoDaddy, so under the Domain Setting I set it using the Subdomain Forwarding (301).
As the result of pointing the domain to Github repository, it will then give all the URLs for both of master
and gh-pages
branch similar like the ones I listed below goes to the preferred domain:
master
By creating CNAME
file on master
branch (check it on my user repository).
http://hyipworld.github.io/
http://www.hyip.world/
http://hyip.world/
gh-pages
By creating the same CNAME
file on gh-pages
branch (check it on my project repository).
http://hyipworld.github.io/maps/
http://www.hyip.world/maps/
http://hyip.world/maps/
As addition to the CNAME
file above, you may need to completely bypass Jekyll processing on GitHub Pages by creating a file named .nojekyll
in the root of your pages repo.
As of Aug 29, 2013, Github's documentation claim that:
Warning: Project pages subpaths like http://username.github.io/projectname will not be redirected to a project's custom domain.
I just discovered, after a bit of frustration, that if you're using PairNIC, all you have to do is enable the "Web Forwarding" setting under "Custom DNS" and supply the username.github.io/project address and it will automatically set up both the apex and subdomain records for you. It appears to do exactly what's suggested in the accepted answer. However, it won't let you do the exact same thing by manually adding records. Very strange. Anyway, it took me a while to figure that out, so I thought I'd share to save everyone else the trouble.
If you are wondering how to get your domain to appear as
www.mydomain.com
instead of redirecting thewww
request tomydomain.com
, try this:
CNAME file on gh-pages branch will have one line:
www.mydomain.com
(instead of mydomain.com
)
No matter your preference on redirection (in other words, no matter what is in your CNAME file on the gs-pages branch), with your DNS provider, you should set it up like this:
A @ 192.30.252.154
A @ 192.30.252.153
CNAME www username.github.io
The selected answer is the good one, but is long, so you might not read the key point:
I got an error with the SSL when accesign www.example.com but it worked fine if I go to example.com
If it happens the same to you, probably your error is that in the DNS configuration you have set:
CNAME www.example.com --> example.com (WRONG)
But, what you have to do is:
CNAME www.example.com --> username.github.io (GOOD)
or
CNAME www.example.com --> organization.github.io (GOOD)
That was my error
These detailed explanations are great, but the OP's (and my) confusion could be resolved with one sentence: "Direct DNS to your GitHub username or organization, ignoring the specific project, and add the appropriate CNAME files in your project repositories: GitHub will send the right DNS to the right project based on files in the respository."
Source: Stackoverflow.com