Search code examples
azureazure-web-app-servicehealth-check

App Service health check is 0% even when in browser website returns 200


I have enabled health check with path "/" for App Service slot.
This path in browser and using curl return 200 status code.
But App Service health check status displays 0.00% (Healthy 0 / Degraded 1)
How is this possible?


Solution

  • One reason I've found is that the Health Checks hit the website on the *.azurewebsites.net URL not any custom domain.

    If you have a canonical redirect setup, that forwards all requests to the custom domain the healthcheck will see that as a fail as it expected a 200 response and is getting a 301/302 response.

    The best solution I've found is to ignore the health check user agent on the canonical redirect, like this:

    <rule name="Canonical Domain Name" enabled="false">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" negate="true" pattern="^customdomain\.com$" />
        <add input="{HTTP_USER_AGENT}" negate="true" pattern="HealthCheck/1\.0" />
        <add input="{HTTP_USER_AGENT}" negate="true" pattern="ReadyForRequest/1\.0\+\(HealthCheck\)" />
      </conditions>
      <action type="Redirect" url="https://customdomain.com/{R:1}" redirectType="Permanent" />
    </rule>