There is a number of resources online trying to explain how to link a domain purchased on Namecheap, to free hosting provided by GitLab Pages. Every single one fails to successfully achieve its goal, so I prepared an ultimate step-by-step guide for everyone facing this issue. Namecheap also sends an email to new users that purchased a domain telling them to ask any question aimed at Namecheap CEO. While I have pointed out in that email that they lack an official documentation on connecting a domain to GitLab pages, it all looks to me like that email is just a very efficient post-sale activity.
Prerequisites
You need to have some stuff up and running before you can start the procedure:
- A purchased domain on Namecheap
- A running instance of GitLab Pages which you use for your free hosting
In my case, the 1st point is my domain, jankovic.dev, and the 2nd one is a repo that deploys a static website under trulex.gitlab.io, since trulex is my username on GitLab.com.
Steps
- Open GitLab repository and go to Settings | Pages, and click on New Domain button
- Write down your domain into the input field and click Create New Domain button
- Copy the verification code’s part starting with gitlab-pages-verification-code=, which you will need for proving the ownership of your domain
- Head over to namecheap Advanced DNS configuration page
- Remove all host records. You can take a screenshot just in case you want to revisit default values in the future.
- Create three new records:
-
Type Host Value TTL A Record @ 35.185.44.232 Automatic CNAME Record your-domain.com <user.gitlab.io>. Automatic TXT Record @ gitlab-pages-verification-code=<your-verification-code> Automatic - Make sure you don’t forget the trailing dot in CNAME Record’s value. Values to be replaced are denoted with <>.
-
- At this point you should be all set up. TLS certificate will be automatically provided by GitLab, if you marked the checkbox in GitLab configuration.
You can now enjoy serving your website under a custom domain bought at namecheap while using free hosting by GitLab.com. Feel free to ask any questions if the procedure didn’t work for you.