Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure App Service Always On with custom domain redirect not hitting default web page

Azure App Service AlwaysOn works perfectly once there is no custom domain set for the web application. Once custom domain is added along with URL rewrite rule to redirect all incoming request to it, application starts to response slowly after some time of inactivity. Logs show that AlwaysOn still pings azure domain and gets HTTP 301 response ans is not trying to request new URL.

Log without custom domain:

2017-06-20 17:17:02 ZZTESTSITE GET / X-ARR-LOG-ID=743965b6-d3e2-42b9-9353-7772f9fbc898 80 - ::1 AlwaysOn ARRAffinity=b5289afa9cd711b67c1fe9137a6e3ff232f80bd3fa1bd96e9fc89992472b4e57 - zztestsite.azurewebsites.net 200 0 0 11433 652 15

Log with custom domain

2017-06-21 13:28:52 ZZTESTSITE GET / X-ARR-LOG-ID=ffcd5992-5019-48ca-a386-76443a8c7226 80 - ::1 AlwaysOn ARRAffinity=b5289afa9cd711b67c1fe9137a6e3ff232f80bd3fa1bd96e9fc89992472b4e57 - zztestsite.azurewebsites.net 301 0 0 553 652 46

URL Rewrite rule:

<rule name="Redirect requests from default azure websites domain to custom one" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^zztestsite\.azurewebsites\.net$" />
  </conditions>
  <action type="Redirect" url="http://mycustomdomain.com" redirectType="Permanent" appendQueryString="false"/>
</rule>

Additionally once SSL in enabled and another rule is added to redirect all requests to HTTPS, same issue will arise.

How can I tackle this problem? I found two possible directions:

  1. Push AlwaysOn to ping custom domain (possibly https as an option)
  2. Change URL Rewrite rule to one allowing AlwaysOn to ping azure domain, but all other shall be redirected

Please advise.

like image 679
Megrez7 Avatar asked Jun 23 '17 14:06

Megrez7


People also ask

Can I change the URL of Azure App Service?

Under Azure App Home page for your app., scroll down on left to "Developer tools" - Select Clone app. Add a new URL and update area etc. You can then go and add your custom domain after, etc.

How do I set always on Azure App Service?

05 On the General settings panel, under Platform settings, select On next to Always on configuration setting to enable the Always On feature for the selected Azure App Services web application. Click Save to apply the changes.

Which of the following URL must be used to manage the Azure Web Apps?

When you create a new website by using Web Apps in Azure, a default sitename.azurewebsites.net domain is assigned to your site. If you add a custom host name to your site and don't want users to be able to access your default *. azurewebsites.net domain, you can redirect the default URL.


1 Answers

Try adding this line to your conditions:

<conditions>
  <add input="{HTTP_HOST}" pattern="^zztestsite\.azurewebsites\.net$" />
  <add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
</conditions>

This tells is not to redirect for the Always On pings. Also note that I removed the MatchAny, as you really want MatchAll here (irrelevant when you only had one).

See here for a more complete example. It's for redirecting http to https, but the core idea is the same with respect to Always On requests. That example is an xdt transform, so it looks a bit different from 'straight' config. In fact you might consider using such xdt instead of polluting your web.config.

like image 153
David Ebbo Avatar answered Sep 20 '22 22:09

David Ebbo