使用 IIS 在 VPS 中托管的域上从 HTTP 到 HTTPS

HTTP to HTTPS on domain hosted in VPS using IIS

我有一个域,其 DNS 设置指向 VPS。

VPS 有一个 IIS 10 实例,它使用 html 使用 bootstrap 托管简单网站。

我安装了 SSL 证书并为 https 部分添加了绑定。

我可以在 http 和 https 上浏览域。

我在 web.config 中添加了以下规则:

<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 上浏览。

我尝试了以下方法:

  1. 已尝试安装 URL Rewrite,但看起来 Windows Server 2016 和 IIS 10 不允许安装

  2. 尝试启用需要 SSL 选项。

    • 这显示 http 格式的网站,没有图像但有文本
    • 网站在https中正常显示

我在这里错过了什么?

我安装错了URL重写。

这篇文章帮助我解决了正确链接的问题。

自动 IIS 在 Windows Server 2016 上将 http 重定向到 https:https://gridscale.io/en/community/tutorials/iis-redirect-http-to-https-windows/