我在 Cloudflare 中使用自定义域 ( https://thebotspeaks.com) 托管我的 git-hub 页面网站 (peps09791.github.io)。 为了启用 HTTPS,我做了以下配置:
在我的 _config.yaml 文件中 我已经相应地设置了 URL 键
网址:“https://peps0791.github.io”
在我的 cloudFlare 仪表板中,我启用了 HTTPS 重写选项以防止混合内容错误。
我还从 CloudFlare 启用了 Flexible SSL。
我没有启用默认的 HTTPS 重定向,因为该网站突破了 HTTPS。在 HTTP 上,它工作正常。
现在,当我尝试使用 HTTPS 访问我的网站时,出现混合内容错误:
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.
从控制台,我可以看到:
<script src="https://peps0791.github.io/assets/js/main.min.js"></script>
<link rel="stylesheet" href="https://peps0791.github.io/assets/css/main.css">
我该如何解决这个问题?
最佳答案
这里的问题是您的 Assets (即您的 CSS 或 JavaScript)正在重定向到您网站的 HTTP 版本。这是因为您的 Assets 直接引用您的 GitHub 站点,而不是启用 Cloudflare 的域。
例如;您的 HTML 在 https://peps0791.github.io/assets/css/main.css
而不是 https://thebotspeaks.com/assets/css/main 引用您的 CSS 文件。 CSS
为了解决这个问题,您似乎需要更新 _config.yaml 文件以具有以下 URL key :
url: "https://thebotspeaks.com"
有关解决各种混合内容问题的更多一般建议可以在 Cloudflare 知识库的以下文章中找到:How do I fix the SSL Mixed Content Error Message?
关于ssl - 使用具有自定义域的 github 页面时出现混合内容错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46672558/