使用具有自定义域的 github 页面时出现混合内容错误
Mixed content error when using github pages with custom domain
我正在使用自定义域 (https://thebotspeaks.com) 和 Cloudflare 托管我的 git-hub 页面网站 (peps09791.github.io)。
为了启用HTTPS,我做了以下配置:
在我的 _config.yaml 文件中
我相应地设置了 URL 键
url: "https://peps0791.github.io"
在我的 cloudFlare 仪表板中,我启用了 HTTPS 重写选项以防止混合内容错误。
我还从 CloudFlare 启用了灵活的 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">
如何解决这个问题?
这里的问题是您的资产(即您的 CSS 或 JavaScript)正在重定向到您网站的 HTTP 版本。这是因为您的资产直接引用您的 GitHub 站点而不是启用 Cloudflare 的域。
例如;您的 HTML 在 https://peps0791.github.io/assets/css/main.css
而不是 https://thebotspeaks.com/assets/css/main.css
引用了您的 CSS 文件
为了解决这个问题,您似乎需要更新 _config.yaml 文件以包含以下 URL 键:
url: "https://thebotspeaks.com"
有关解决各种混合内容问题的更多一般性建议,请参阅 Cloudflare 知识库中的以下文章:How do I fix the SSL Mixed Content Error Message?
显然适合我。 Github 回购中 CNAME
文件内的网站没有 https
前缀。所以我添加了https://。它奏效了。
干杯
P.S: 1年后解决了这个问题,你相信吗。
添加这个帮助我处理了在启用 HTTPS 保护的自定义域上 GitHub 页面上的混合内容错误:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
我正在使用自定义域 (https://thebotspeaks.com) 和 Cloudflare 托管我的 git-hub 页面网站 (peps09791.github.io)。 为了启用HTTPS,我做了以下配置:
在我的 _config.yaml 文件中 我相应地设置了 URL 键
url: "https://peps0791.github.io"
在我的 cloudFlare 仪表板中,我启用了 HTTPS 重写选项以防止混合内容错误。
我还从 CloudFlare 启用了灵活的 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">
如何解决这个问题?
这里的问题是您的资产(即您的 CSS 或 JavaScript)正在重定向到您网站的 HTTP 版本。这是因为您的资产直接引用您的 GitHub 站点而不是启用 Cloudflare 的域。
例如;您的 HTML 在 https://peps0791.github.io/assets/css/main.css
而不是 https://thebotspeaks.com/assets/css/main.css
为了解决这个问题,您似乎需要更新 _config.yaml 文件以包含以下 URL 键:
url: "https://thebotspeaks.com"
有关解决各种混合内容问题的更多一般性建议,请参阅 Cloudflare 知识库中的以下文章:How do I fix the SSL Mixed Content Error Message?
显然适合我。 Github 回购中 CNAME
文件内的网站没有 https
前缀。所以我添加了https://。它奏效了。
干杯
P.S: 1年后解决了这个问题,你相信吗。
添加这个帮助我处理了在启用 HTTPS 保护的自定义域上 GitHub 页面上的混合内容错误:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">