Custom domain for GitHub project pages
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?
So I figured it out. James McLaughlin gave me the nudge I needed.
To Setup a custom domain for a gh-pages Project Pages repo that handles www.yourdomain.com and yourdomain.com (assumes you already have a gh-pages branch on your repo):
yourdomain.com
. Commit then push. cname
records. One for the root apex (@) and one for www. Both point to YOURusername.github.io
. If your DNS provider does NOT support ALIAS
records on the root apex (@), simply create A
records that point to 192.30.252.153
and 192.30.252.154
Wait til your name servers update:
dig yourdomain.com +nostats +nocomments +nocmd
Overview
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:
What you will get
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:
1. Create A records
For the A records, point @ to the following ip addresses:
@: 192.30.252.154
@: 192.30.252.153
These are the static Github IP addresses from which your content will be served.
2. Create a CNAME Record
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.
eg
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:
3. Create a CNAME file
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.
eg
nicholasjohnson.com
This file tells GitHub to use this repo to handle traffic to this domain.
4. Wait
Now wait 5 minutes, your project page should now be live.
If you are wondering how to get your domain to appear as www.mydomain.com
instead of redirecting the www
request to mydomain.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
链接地址: http://www.djcxy.com/p/7850.html
下一篇: GitHub项目页面的自定义域