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

chr*_*ris 4 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,所以我的网站现在是 http s。然而,当从我的服务器请求文件时,我给他们的服务器上的 HTML 仍然是 http。

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

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

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

我的主人是 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>
Run Code Online (Sandbox Code Playgroud)

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

谢谢!

sid*_*ker 6

您可以使用Content-Security-Policy: upgrade-insecure-requests标题为您的网站提供服务。

upgrade-insecure-requestsCSP指令还可以使用指定的meta元素:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
Run Code Online (Sandbox Code Playgroud)

HTTP Content-Security-Policy (CSP)upgrade-insecure-requests指令指示用户代理将站点的所有不安全 URL(通过 HTTP 提供的)视为已替换为安全 URL(通过 HTTPS 提供的)。该指令适用于具有大量需要重写的不安全旧 URL 的网站。

当前所有浏览器都支持upgrade-insecure-requests指令。


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