Setting up GitLab Pages with Cloudflare Certificates

Marcia Ramos ยท
Feb 7, 2017 ยท 4 min read

Cloudflare SSL/TLS certificates are free to use. If you want your GitLab Pages site to work with them, it's as simple as could be. There's just a trick you might not know about (yet)!

We assume you're familiar with SSL/TLS, DNS, GitLab Pages, and Cloudflare.

On this page


With GitLab Pages, you can deploy a static website with custom domains/subdomains and SSL/TLS support.

This tutorial responds to the issue "Support Cloudflare CA please!", and other cases where GitLab users asked specifically how to add a Cloudflare certificate to GitLab Pages. ๐Ÿ˜‰ Anything else is outside the scope of this post.

If you don't know how to set up your GitLab Pages site, or why you should care about SSL/TLS:

In case you don't know about it yet, we're bringing GitLab Pages to GitLab Community Edition! ๐ŸŽ‰

Step-by-step quick guide

To create this step-by-step guide, I'll use my subdomain as an alias for the website originally deployed to

The codebase is a simple Jekyll site built with its default theme, available at

STEP 1. DNS record

On Cloudflare, navigate to the tab DNS and create a new DNS record (CNAME or A) pointing your subdomain (CNAME) or root domain (A) to your GitLab Pages site.

The image below shows both CNAME and A records (for the purposes of this demo), but of course, you will only need one of them. For this example, I used the CNAME record pointing to my subdomain

set up Cloudflare DNS

For projects on, the DNS A record should point your custom domain to GitLab Pages' server IP address

Note: This GitLab Pages IP address for changed from to in August 2018.

If you'd already set this up, just jump to the second step.

STEP 2. Generate your certificate

  1. Navigate to the tab Crypto.
  2. Generate your certificate:

    generate certificate

  3. Choose the domain, subdomain, or wildcard to apply the cert to, then click Next:


  4. Your certificate and private key have been generated. Leave the tab and the modal window open:

    modal with certificate

STEP 3. Add the custom (sub)domain and the certificate to your GitLab Pages project

From a new tab, go to GitLab, and navigate to your project's Settings > Pages > + New Domain:

configure GitLab Pages

Copy the PEM certificate and the private key from the tab you've left open on Cloudflare, and paste it into their respective fields in GitLab:

Add PEM certificate to Pages

STEP 4. The trick

Cloudflare doesn't combine both PEM and root certificates in one, so we need to copy the root certificate (aka "intermediate") Cloudflare Origin CA โ€” RSA Root from the code block below, and paste it below your certificate (PEM) just added to GitLab:

Copy Cloudflare's Origin CA โ€” RSA Root:


Paste it below your PEM certificate (jump a line between the last row of your cert -----END CERTIFICATE----- and the first row of the intermediate cert -----BEGIN CERTIFICATE-----):

Add intermediate certificate

STEP 5. Apply the changes

  1. Click Create New Domain.
  2. Ta-da! ๐ŸŽ‰


It works fine with the encryption set to "Full" or "Full (strict)" on Cloudflare:

Set Cloudflare SSL to full strict

Wrap up

That's it, now your site runs on HTTPS with a custom domain and a free Cloudflare certificate, valid up to 15 years!

Comments, questions, suggestions? Please comment below or tweet @GitLab! ๐Ÿ˜€

Cover image by Rita Morais, licensed under CC0 1.0.

Edit this page View source