在 Azure 应用服务中,可以通过 web.config 文件或 Azure 门户中的自定义域边栏选项卡将 HTTP 流量重定向到 HTTPS。是否可以在不进行重定向的情况下完全禁用HTTP?
这是实现此目的的一种方法:
- 转到 Web 应用的 Kudu 控制台
- 进入
D:homesite
文件夹 -
在该文件夹中创建一个名为
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(您可以在 <action>
标记中自定义响应(。