【问题标题】:Is it possible to disable HTTP on an azure app service, not just redirect it to HTTPS是否可以在 Azure 应用服务上禁用 HTTP,而不仅仅是将其重定向到 HTTPS
【发布时间】:2018-07-01 14:27:54
【问题描述】:

在 Azure 应用服务中,您可以通过 web.config 文件或 Azure 门户中的自定义域刀片将 HTTP 流量重定向到 HTTPS。是否可以在不进行重定向的情况下完全禁用 HTTP?

【问题讨论】:

    标签: azure azure-web-app-service


    【解决方案1】:

    这是实现此目的的一种方法:

    • 转到 Web 应用程序的 Kudu 控制台
    • 进入D:\home\site文件夹
    • 在该文件夹中创建一个名为 applicationhost.xdt 的文件,其内容如下(您可以从本地计算机拖放它):

      <?xml version="1.0"?>
      <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        <location path="%XDT_SITENAME%" xdt:Transform="InsertIfMissing" xdt:Locator="Match(path)">
          <system.webServer xdt:Transform="InsertIfMissing">
            <rewrite xdt:Transform="InsertIfMissing">
              <rules xdt:Transform="InsertIfMissing">
                <rule name="Disable HTTP" enabled="true" stopProcessing="true">
                  <match url="(.*)" ignoreCase="false" />
                  <conditions>
                    <add input="{HTTPS}" pattern="off" />
                    <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
                  </conditions>
                  <action type="CustomResponse" statusCode="401" />
                </rule>
              </rules>
            </rewrite>    
          </system.webServer>
        </location>
      </configuration>
      

    这将使http请求失败并返回401(您可以在&lt;action&gt;标签中自定义响应)。

    【讨论】:

    • 太棒了。这就是我每天登录 StackOverflow 的原因。
    • 这也适用于基于 linux 的应用服务吗?它似乎对我不起作用。
    • @JoostPielage 现在以下复选框适用于我:Azure Portal > App Service > {some-web-app} > TLS/SSL settings > HTTPS Only
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2018-02-01
    • 2022-01-08
    • 2013-12-24
    • 1970-01-01
    • 2019-06-24
    相关资源
    最近更新 更多