loading...

How to setup google domain for gitlab pages with http and https

benteoneb profile image Ben Farcy ・3 min read

If like me, you want to redirect a gitlab pages website to a domain you own through google domain, this is for you.
I found the information for github pages here, but was looking for the gitlab specifics and could not find it easily.

Prerequisites

  • Purchased a google domain, such as example.com
  • Set up a gitlab pages website, available on a gitlab project link

Set up

Gitlab configuration

  • 1. Go to Setting/Pages, uncheck Force HTTPS (require valid certificates)
  • 2. Go to New Domain, enter the name of your demain such as example.com, then confirm with Create New Domain
  • 3. Still in Setting/Pages, go to the Details of your newly added domain example.com
  • 4. Copy to clipboard the generated Verification status string that looks like that: _gitlab-pages-verification-code.example.com TXT gitlab-pages-verification-code=1234abcd

Google domain configuration

Warning: if you just bought your google domain, you may not be able to see the effect of below actions just yet. DNS propagation can take several hours.

  • 5. Go to your google domain account and manage your domain such as example.com
  • 6. Go to DNS on the left pane and scroll down to Custom resource records
  • 7. Add a first record with default name @, default type A, default TTL 1H and IPV4 address 35.185.44.232. This is the gitlab pages IP, you can check it out here
  • 8. Add a second record with default name @, type TXT default TTL 1H and paste your gitlab verification code here

At this step, you can check that the record is well set by pinging your domain. You can try a ping example.com, or a dig example.com, in your terminal and the gitlab pages IP should show up. If not, check the steps above.

  • 9. Go back to your gitlab, Setting/Pages, go to the Details of your domain example.com, check the Verification Status and retry verification if needed.

Voilà, now when you go to http://example.com you should see your gitlab page. Do not worry too much if you see a 404 error from Gitlab, it can take several minutes to propagate.

You can stop here or go on to unlock www and https.

World Wide Web prefix

If you want to have the www prefix work as well, follow the same steps as before, but with www.example.com:

  • 10. Go to gitlab Setting/Pages
  • 11. Go to New Domain, enter the name of your domain with www like www.example.com, then confirm with Create New Domain
  • 12. Still in Setting/Pages, go to the Details of your newly added domain www.example.com
  • 13. Copy to clipboard the generated Verification status string that looks like that: _gitlab-pages-verification-code.example.com TXT gitlab-pages-verification-code=1234abcd
  • 14. Go again tp your google domain account and manage your domain such as example.com
  • 15. Go to DNS on the left pane and scroll down to Custom resource records
  • 16. Add a third record with default name www, default type A, default TTL 1H and IPV4 address 35.185.44.232.
  • 17. Add a second record with default name www, type TXT default 1H and paste your gitlab verification code here
  • 18. Go back to your gitlab, Setting/Pages, go to the Details of your domain www.example.com, check the Verification Status and retry verification if needed.

Voilà, now when you go to http://www.example.com you should see your gitlab page. Again, do not worry too much if you see a 404 error from Gitlab, it can take several minutes to propagate.

HTTPS

Juste make sure to certify at the same time your example.com and your www.example.com domain, by putting both domain in the certbot command:

sudo certbot certonly -a manual -d example.com -d www.example.com --email name@email.com

That's all, you should now have access to your website through:

  • http://www.example.com
  • http://example.com
  • https://www.example.com
  • https://example.com

Discussion

pic
Editor guide