AlwaysOn function does not work correctly when using the rewrite rule to redirect http to https

I have an Azure PaaS instance running Spring -Boot packaged "war" inside the Tomcat8 container. The problem is that after a period of activity, the activity of "java" is destroyed.

enter image description here

The above image looks as if the tomcat process had not been killed.

The tomcat process starts again only when I again make any request to the server.

If my understanding is correct, the flag "WEBSITE_SCM_ALWAYS_ON_ENABLED" is intended to keep the instance alive, that is, "w3wp", and not for Tomcat.

One solution to this problem is to "poll" my server with a simple "health" request to keep it.

It would be better if there was some kind of Azure or Spring-boot configuration for my "httpPlatformHandler" so that I could prevent her from sleeping.

Any help is appreciated.

**** UPDATE ****

With additional help from @DavidEbbo, the problem was traced back to the URL rewrite rule that I used to go from “http” to “https” URLs. The "AlwaysOn" request is on HTTP (port 80), and so whenever the Azure request hits, it receives a redirect (301) as a response. Still awaiting a decision.

+5
source share
1 answer

The root of the problem is that the URL rewrite rule that you use to redirect http to https prevents AlwaysOn searches from reaching your Java application.

Fortunately, there is a solution.

Solution # 1: use the XDT transform

Use the following steps:

  • Remove the rewrite rule from your web.config
  • Instead, use the Kudu Console (or FTP, but it's harder) to create a file called applicationHost.xdt in the site folder (i.e. d:\home\site\applicationHost.xdt ). Hint: you can enter touch applicationHost.xdt in the Kudu Console to create an empty file.
  • Edit this file and paste the found XDT file here in the section "Redirect HTTP traffic to https".
  • Save the file and restart your site from the portal.

Note that AlwaysOn requests will still look like 301 in http logs, but everything will continue (i.e. Java will wake up).

Solution # 2: make changes directly to your web.config

Alternatively, if you do not want to use the XDT transform and want to save everything in your web.config, you can simply add the missing fragments. In particular, you will need two changes (corresponding to the XDT above):

Add this condition to the rewrite rule:

 <add input="{WARMUP_REQUEST}" pattern="1" negate="true" /> 

Add this applicationInitialization section to system.webServer :

 <applicationInitialization> <add initializationPage="/" /> </applicationInitialization> 

But I propose the XDT approach, because it does not require complex changes and keeps these "dirty" things separate from your code base.

Original answer

The correct way to enable Always On is to set it to On on the Azure portal. WEBSITE_SCM_ALWAYS_ON_ENABLED not what you can install, but it is what Azure installs as a result of enabling Always On.

Once you enable Always On, the root of your site (i.e. / ) will hit every few minutes, which should support it.

If you need extra paths to hit, you can use applicationInitialization. More details here .

+3
source

Source: https://habr.com/ru/post/1237646/


All Articles