html - 获得 SSL,现在所有请求的文件都被阻止(混合内容)

标签 html windows ssl web-config mixed-content

我有一些客户在他们的页面上使用我提供的 HTML。该 HTML 链接到我服务器上的文件(JS、CSS、图像等)。

我给他们的示例:
<link type="text/css" rel="stylesheet" href="http://www.example.org/this.css" />

我刚刚获得 SSL,所以我的站点现在是 https。但是,当从我的服务器请求文件时,我提供给他们的服务器上的 HTML 仍然是 http。

正因为如此,他们收到混合内容警告并且内容被阻止。像这样:

混合内容:位于“https://www.example.org/”的页面' 通过 HTTPS 加载,但请求了不安全的样式表 ' http://www.example.org/file.css '.此请求已被阻止;内容必须通过 HTTPS 提供。

我不能让我所有的客户都将他们所有页面上的所有链接都更改为“https”,以便防止警告/阻塞。那将是一场噩梦。

我的主机是 GoDaddy。我的服务器是 Windows 服务器,IIS:7.0,ASP.Net 运行时版本:4.0/4.5。

我如何通过 web.config 解决这个问题?我目前的规则是:

<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                </conditions>
                <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

我想要发生的是允许所有外部 http 请求到我的 https 服务器。

谢谢!

最佳答案

您可以使用 Content-Security-Policy: upgrade-insecure-requests header 为网站提供服务.

upgrade-insecure-requests也可以使用 meta 指定 CSP 指令元素:

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

The HTTP Content-Security-Policy (CSP) upgrade-insecure-requests directive instructs user agents to treat all of a site's insecure URLs (those served over HTTP) as though they have been replaced with secure URLs (those served over HTTPS). This directive is intended for web sites with large numbers of insecure legacy URLs that need to be rewritten.

upgrade-insecure-requests指令 is supported in all current browsers .


顺便说一句,“位于 'https://www.example.org/' 的页面已通过 HTTPS 加载,但请求了不安全的样式表 'http://www.example.org/file.css' 消息不是任何人都可以通过 <link…href="http://www.example.org/this.css" /> 获得的消息自己网站的 HTML 中的元素。他们获得该消息的唯一方法是直接导航到 https://www.example.org/ .

关于html - 获得 SSL,现在所有请求的文件都被阻止(混合内容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44144435/

相关文章:

haskell - 如何向 http-client-tls 提供客户端证书?

javascript - 延迟升级到 HTTPS (TLS/SSL)

c# webbrowser 控制打印

javascript - 当 href 标签中的 onMouseOver 时,如何在 jQuery 中分配动态元素 id?

c++ - 当我从 OnCopyData 返回 TRUE 时,为什么会触发断点?

windows - Gitlab 运行者 : verify vs status

javascript - 如何使用页面上所有图像的图像 src 填充 alt 字段

javascript - 使用 jQuery 的 .load 方法从页面返回一个元素

windows - Windows中runonce的局限性

node.js - 如何在 WHM CentOS7 中为与虚拟主机一起安装的 Socket.IO 设置 SSL?