Today we’re going to share with you the way to use multiple github custom domains as we did with our
teracy-official organization account.
http://teracy-official.github.io will point to
teracy-official.github.io/<project_name> will point to the project’s
if it’s available.
With our requirements, we don’t want to use
http://teracy.org only. That’s why we have to setup multiple github custom
From the very first days, we setup
blog.teracy.com to map to the organization page at
teracy-official.github.io repository. We could get what we want by:
- adding CNAME
teracy-official.github.iovia DNS manager
- adding CNAME file with ‘blog.teracy.com’ content to
However, by default, this domain will be used for all other project pages if you don’t specify th project custom domains.
For example, by setting up like above and we have
teracy-dev project with
When we access
teracy-official.github.io/teracy-dev, it will be redirected to
blog.teracy.com/teracy-dev project page by github custom domain mechanism, and this was not what
We also want
teracy-dev project page should be served by
http://teracy-dev.teracy.org, it’s also
every easy just configure CNAME and add CNAME file to
gh-pages branch like we did with the blog
- add CNAME
- add CNAME file with ‘teracy-dev.teracy.org’ content to
Wait for DNS change to be updated and access
teracy-dev.teracy.org, it should point to
There is a minor problem though:
teracy-official.github.io/teracy-dev will not be automatically redirected to
If we configure the root domain http://teracy.org to map to
teracy-official.github.io/teracy-dev will be redirected to
github custom domain mechanism. With this approach, an issue is raised: it will also introduce more
duplicated links between
teracy.org/teracy-dev. This duplicated issue
should be avoided.
So we decided to have a router on
teracy.org by using
2. Solution with
Actually, before setting up our custom domains, existing links exists and we have to maintain these by redirecting. We have these requirement rules:
- By adding ‘teracy.org’ to teracy-official.github.io/tree/master/CNAME => by github mechanism:
- Our nginx rules:
1 2 3
- Fix existing links by redirecting as these links are already indexed by search engines:
The detailed requirements are at: https://github.com/teracy-official/teracy-official-blog/issues/20
2.2. How to setup and configure
With the above requirement rules, this is how to configure our
Create a new nginx host file at
/etc/nginx/sites-available/teracy.org and symlink it to
/etc/nginx/sites-enable/teracy.org with the content as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Just by applying rules from
HttpRewriteModule 3, we could solve the problems easily.
That’s it. Have a nice day and happy hacking!
P/S: Sure that you can have many other solutions like Apache + Modrewrite, etc., but to us,
is more lightweight, simpler and flexible enough. We also use
nginx to proxy and protect many
other HTTP(S) resources for our projects.