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.
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
-
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:
- Go to Route 53 console
- At navigation pane at the upper right on console, select zone (e.g.“us-east-1”).
- Select record and click “Edit record”.
- 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” |
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
- GitLab Docs - Custom domains and SSL/TLS Certificates
- Stackoverflow - Gitlab Pages: Failed to verify domain ownership
- Youtube - Gitlab - How to Publish a Website with GitLab Pages
- gitlab.jp blog - 独自ドメインを設定する
- aws - Amazon Route 53 開発者ガイド - ウェブサイトやウェブアプリケーションへのインターネットトラフィックのルーティング
- aws - Amazon Route 53 開発者ガイド - レコードの編集
- aws - Amazon Route 53 Developpr guide - Values for simple records
- dns-sd.org - Trailing Dots in Domain Names
- aws - Amazon Route 53 Developpr guide - Set up DNS record for Pages
- aws S3 - Route 53 に登録されたカスタムドメインを使用した静的ウェブサイトの設定