'Mixed content error when using github pages with custom domain

I'm hosting my git-hub pages website (peps09791.github.io) using a custom domain (https://thebotspeaks.com) with Cloudflare. To enable HTTPS, I have done the following configurations:

  1. In my _config.yaml file I have set the URL key accordingly

    url: "https://peps0791.github.io"

  2. From my cloudFlare dashboard, I have enabled option of HTTPS rewrites to prevent mixed content error.

  3. I have also enabled Flexible SSL from CloudFlare.

I haven't enabled default HTTPS-redirection because the website breaks over HTTPS. On HTTP, it works fine.

Right now, when I try to access my website using HTTPS, I get mixed content error:

Mixed Content: The page at 'https://thebotspeaks.com/' was loaded over HTTPS, but requested an insecure image 'http://thebotspeaks.com/assets/images/bio-photo.jpg'. This content should also be served over HTTPS.

09:54:45.323 (index):1 Mixed Content: The page at 'https://thebotspeaks.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://thebotspeaks.com/assets/css/main.css'. This request has been blocked; the content must be served over HTTPS.

09:54:45.785 (index):1 Mixed Content: The page at 'https://thebotspeaks.com/' was loaded over HTTPS, but requested an insecure script 'http://thebotspeaks.com/assets/js/main.min.js'. This request has been blocked; the content must be served over HTTPS.

From console, I can see this:

<script src="https://peps0791.github.io/assets/js/main.min.js"></script>

<link rel="stylesheet" href="https://peps0791.github.io/assets/css/main.css">

How do I resolve this issue?



Solution 1:[1]

Adding this helped me to deal with the Mixed Content error on GitHub pages on a custom domain secured with enabled HTTPS:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

Solution 2:[2]

Apparently for me. The website inside CNAME file in Github repo did NOT had https prefix. So I added https://. and it worked.

Cheers

P.S: Fixed this problem after 1 year, can you believe.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nikolas Charalambidis
Solution 2 igauravsehrawat