Tommy
Tommy

Reputation: 370

Is it possible to disable HTTP on an azure app service, not just redirect it to HTTPS

In azure app services you are able to redirect HTTP traffic to HTTPS either via the web.config file or through the custom domains blade in azure portal. Is it possible to disable HTTP completely without doing a redirect?

Upvotes: 9

Views: 4721

Answers (1)

David Ebbo
David Ebbo

Reputation: 43183

Here is a way to achieve this:

  • Go to Kudu console for the Web App
  • Go into the D:\home\site folder
  • Create a file called applicationhost.xdt in that folder, with the following content (you can drag/drop it from your local machine):

    <?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>
    

This will make http requests fail with 401 (you can customize the response in the <action> tag).

Upvotes: 13

Related Questions