Linking Namecheap to GitLab Pages - the ultimate step-by-step guide

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. namecheap+gitlab

Prerequisites

You need to have some stuff up and running before you can start the procedure:

  1. A purchased domain on Namecheap
  2. 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

  1. Open GitLab repository and go to Settings | Pages, and click on New Domain button
    1. Write down your domain into the input field and click Create New Domain button
    2. Copy the verification code’s part starting with gitlab-pages-verification-code=, which you will need for proving the ownership of your domain
  2. Head over to namecheap Advanced DNS configuration page
    1. Remove all host records. You can take a screenshot just in case you want to revisit default values in the future.
    2. Create three new records:
      1. 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
      2. Make sure you don’t forget the trailing dot in CNAME Record’s value. Values to be replaced are denoted with <>.
  3. 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.


See also