Sub topic 11
Enabling HTTPS
This chapter assumes you have a published Pages site. For a custom domain, it also assumes the domain's DNS records already point at GitHub Pages and the CNAME file is in place, as covered in the previous two chapters.
What HTTPS gives you
HTTPS encrypts traffic between the visitor's browser and the server. It also lets the browser confirm it is talking to the right host. The server proves its identity with a TLS certificate issued by a certificate authority.
GitHub Pages handles certificates for you. You never generate, upload, or renew one.
Sites on github.io
A site at USERNAME.github.io or ORG.github.io is served over HTTPS with a GitHub-managed certificate. In most cases there is nothing to set up.
To force every visitor onto HTTPS, open the repository's Settings, then Pages, and tick Enforce HTTPS. With this on, requests to http:// URLs are redirected to https://.
Sites on a custom domain
For a custom domain, GitHub requests a certificate from Let's Encrypt. It does this after it detects that your DNS records point at Pages. The sequence looks like this:
Issuance is not instant. It can take up to an hour after DNS is correct. Until it finishes, the Enforce HTTPS checkbox is greyed out or shows a message that the certificate is being created. Wait, then reload the settings page.
Check your DNS first
Most certificate delays come from DNS that does not match what Pages expects. Query your records from a terminal:
dig example.com +noall +answer
dig www.example.com +noall +answerThe apex domain should return the four GitHub addresses. The www name should return a CNAME to USERNAME.github.io. Remove any extra A or AAAA records that point somewhere else. A record at another host can make the domain check fail.
CAA records
A CAA record limits which certificate authorities may issue certificates for your domain. If you have one that does not list Let's Encrypt, issuance fails. Add this entry alongside your existing ones:
example.com. CAA 0 issue "letsencrypt.org"If you have no CAA records, no action is needed.
Mixed content
After you enforce HTTPS, a page can still break if it loads resources over plain HTTP. Browsers block many of these requests, which is called mixed content. Typical symptoms are missing styles, scripts that do not run, or images that do not appear.
<!-- Blocked on an HTTPS page -->
<link rel="stylesheet" href="http://example.com/style.css">
<!-- Works -->
<link rel="stylesheet" href="https://example.com/style.css">
<!-- Also works, and stays on the same host -->
<link rel="stylesheet" href="style.css">Prefer relative paths for your own files. Use https:// for anything hosted elsewhere. The browser's developer console names each blocked request.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| **Enforce HTTPS** is disabled | Certificate not issued yet, or DNS is wrong | Verify DNS with `dig`, then wait up to an hour |
| Browser warns about the certificate | Domain was changed recently, or the certificate does not cover that name | Remove and re-add the custom domain in Pages settings |
| Issuance never completes | A CAA record excludes Let's Encrypt | Add the `letsencrypt.org` CAA entry |
| Page loads but looks unstyled | Mixed content | Change `http://` links to `https://` or relative paths |
Exercise
You added a custom domain and correct DNS records an hour ago. The Enforce HTTPS checkbox is still disabled. List the first two things you check and one action you can take if both look correct.
Show answer
First, run dig on the apex domain and the www name to confirm they return the GitHub A records and the CNAME to USERNAME.github.io, with no conflicting records. Second, check whether a CAA record exists that does not allow letsencrypt.org. If both look correct, remove and re-add the custom domain in Settings > Pages to restart certificate provisioning, then wait and reload.
Exercise
After enabling Enforce HTTPS, your page loads but the stylesheet is missing. The HTML contains href="http://cdn.example.net/site.css". What is the cause and the fix?
Show answer
The page is HTTPS but requests the stylesheet over HTTP, which the browser blocks as mixed content. Change the link to https://cdn.example.net/site.css, or host the file in the repository and use a relative path.