使用 Azure 的 http 到 https 端点

http to https endpoint with Azure

借助 AWS,我可以使用 API 网关和 CloudFront 将 http 端点转换为 https 端点,并且我得到如下所示的 URL,

https://4z9giyi2c1.execute-api.us-west-2.amazonaws.com/test/petstore/pets?type=fish

如何使用 Azure 进行同样的操作?

有一个开源扩展:

  1. 转到您的 Azure 应用服务 Development Tools 栏,您可以在那里找到 Extensions 选项卡并单击添加。

  2. 之前有一个扩展名Redirect HTTP to HTTPS但是我找不到它知道,但是我找到了一个新的扩展名Security Settings: HTTPS Redirect w/KeepAlive Support, Headers incl HSTS, CSP, and More. "Medium strength".

  1. 添加扩展并重新启动网络。

有关此扩展的更多详细信息,check the source code on github. The mainly important file is applicationhost.xdt。它写入规则 "redirect HTTP to HTTPS".

          <rewrite xdt:Transform="InsertIfMissing">
                <rules xdt:Transform="InsertIfMissing" lockElements="clear">
                    <rule name="redirect HTTP to HTTPS" enabled="true" stopProcessing="true" lockItem="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                            <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
                            <add input="{HTTP_USER_AGENT}" pattern="Initialization" negate="true" ignoreCase="false" />
                            <add input="{HTTP_USER_AGENT}" pattern="SiteWarmup" negate="true" ignoreCase="false" />
                            <add input="{HTTP_USER_AGENT}" pattern="AlwaysOn" negate="true" ignoreCase="false" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>

Update

CloudFront 是 AWS CND,它是一个分布式服务器网络,可以有效地向用户提供 Web 内容。 CDN 将缓存内容存储在靠近最终用户的入网点 (POP) 位置的边缘服务器上,以最大程度地减少延迟。 Azure 的 CDN 是 Azure Content Delivery Network (CDN).

如果您的目标是为您的应用程序强制执行 HTTPS,那么 CDN 可能不是最佳可用选项,因为 CDN 用于向全球分散的客户提供低延迟和高可用性的静态内容。虽然,您可以将 HTTPS 与 CDN 一起使用,但这会产生使用 CDN 服务的费用。

So if your primary goal is to use HTTPs then below procedure is for binding SSL to your custom domian name to enforce HTTPS communication with your website.

使用 Microsoft Azure,您可以将您的 Webapp 与 SSL 证书绑定,以便通过 https 访问它。为此,您需要拥有;

  1. 创建了应用服务应用程序

  2. 将自定义 DNS 名称映射到您的应用服务应用程序

  3. 已从受信任的证书颁发机构获取 SSL 证书

  4. 拥有用于签署 SSL 证书请求的私钥

在您的 Azure 门户中,访问您要为其添加 SSL 证书的 Web 应用程序。然后点击应用左侧导航中的 SSL 设置。然后单击 上传证书 将其添加到您的网络应用程序中。

之后,在 SSL 绑定部分,单击 添加绑定 。在“添加 SSL 绑定”页面中,使用下拉列表 select 要保护的域名和要使用的证书。

强制执行 HTTPS:-

您可以将所有 HTTP 请求重定向到 HTTPS 端口。 在您的应用程序页面的左侧导航中,select SSL 设置。然后,在HTTPS Only、select上。

有关更多信息和完整教程,请访问 Tutorial: Bind an existing custom SSL certificate to Azure App Service

But, if you intended to use CDN services along with secure HTTPs connection then below is the procedure to use Azure CDN to enable a custom domain with SSL.

  1. 在 Azure 门户中,浏览到您的 Azure CDN 来自 Microsoft 的标准版、来自 Akamai 的 Azure CDN 标准版、来自 Verizon 的 Azure CDN 标准版或来自 Verizon 的 Azure CDN Premium 配置文件。
  2. CDN 端点列表中,select 端点包含您的自定义域。
  3. 自定义域列表中 ,select 您要为其启用 HTTPS 的自定义域。
  4. 证书管理类型下,select CDN 管理。
  5. Select 打开 启用 HTTPS。

有关详细信息,请参阅 Configure HTTPS on an Azure CDN custom domain

如果您只想将 HTTP 流量重定向到 Azure CDN 中的 HTTP,则只需使用 Azure CDN 规则引擎创建 URL 重定向规则。有关更多信息,请参阅 HTTP-to-HTTPS redirection

Azure Front Door 是您需要的选项。

此服务在一项服务中提供了组合的 Web 应用程序防火墙、流量管理器(用于路由)和 CDN。更重要的是,与 Azure 提供的其他普通 CDN 不同,它允许 SSL 终止:

您可以将路由规则配置为仅接受 http 或 https 之一,或同时接受两者,然后路由详细信息允许您指定是否将请求传递为 HTTPS Only、HTTP Only(您想要的)或 "Match Request":

然后您可以为重定向到 HTTPS 的 non-HTTPS 流量设置后续规则,强制所有流量安全。