Contents

Custom Domain for GitLab Pages

I want to migrate my former site on wordpress to here (Hugo on gitlab.io) with keeping domain.

I tried several ways, but the best is just following official GitLab Docs - Custom domains and SSL/TLS Certificates].

  • Existing my domain
  • Website ()

1. Requirements:

  • A GitLab Pages website up and running, served under the default Pages domain (*.gitlab.io, for GitLab.com)
  • A custom domain name example.com or subdomain subdomain.example.com
  • Access to your domain’s server control panel to set up DNS records:
    • A DNS A or CNAME record pointing your domain to GitLab Pages server.
    • A DNS TXT record to verify your domain’s ownership.
Note
Original site was the project Page named on “example.gitlab.io/site”. As requirement says Pages running served under the default Pages domain(*.gitlab.io, for GitLab.com), I need to change it into default page.

2. (Gitlab Pages) default domain setting

According to - Youtube - Gitlab - How to Publish a Website with GitLab Pages, changing project path to default domain (in my case “example.gitlab.io”) works.

Gitlab.com > Settings > General > Advanced > Change path

  • Before: site(same as the project name)
  • After: example.gitlab.io
Note
  • It will break path related settings (ex. git, gitlab or local project settings). Before doing this, I committed and pushed everything just in case.

  • After changing path, all I did was:

    • Change .git/config “.git” file name(“site.git”) to “example.gitlab.io.git”
    • Change baseURL in config.toml to “https://example.gitlab.io/"

3. (GitLab Pages) enable custom domain

Gitlab.com > Settings > Pages

3.1. Add Domain

  • Check “Fource HTTPS(requires valid certificate)”
  • Click “New Domain” and register my domain

3.2. Check CNAME and TXT for DNS setting

  • Copy
    • CNAME
    • Verification Status

3.3. Enable certificate

  • Check to enable “Automatic certificate management using Let’s Encrypt.

4. (DNS) Edit Amazon Route 53 record

Following guidance by AWS Route 53 developer guide, edit DNS record by:

  1. Go to Route 53 console
  2. At navigation pane at the upper right on console, select zone (e.g.“us-east-1”).
  3. Select record and click “Edit record”.
  4. After editing, save record.

I added two records:

Record name Type Routing policy Value / traffic destination
blog.example.com CNAME Simple example.gitlab.io
_gitlab-pages-verification-code.app.example.com TXT Simple “gitlab-pages-verification-code=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
Note
For “Value” in record, I added the destination domain without trailing dot(example.gitlab.io.) and that seems to work.

Ref. https://docs.gitlab.com/ee/user/project/pages/custom_domains_ssl_tls_certification/#for-subdomains


5. (GitLab Pages)Custom domain verification

Gitlab > (project) > Settings > Pages > Domains - Edit > Verification status

  • The verification completed after a few minutes I registered the records to AWS Route53.
  • “Let’s Encrypt” confirmation runs for around 10 minutes, then I could access to the site over HTTPS.

References