How to fix warning: “Application evaluated unhealthy due to redirection.” on Azure Health Check Feature

£可爱£侵袭症+ 提交于 2021-02-10 06:43:07

问题


I ran "Diagnose and solve problems" on Azure dashboard inside one of the app services, and then I got this critical risk alert: "Application evaluated unhealthy due to redirection.".

Recommended actions is:

If the application has HTTP to HTTPS redirectoin, consider one of the following solutions.

a. Enable 'HTTPs Only' from the TLS/SSL settings blade for the respective App Service. This will force health check pings to over 443.

b. Modify the Application logic/ad a URL Rewrite rule so that requests from the user agents – ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0 are not redirected.

I already enable 'HTTPs Only' as suggested on point (a), but I don't know how to do point (b). How to modify the Application logic/ad a URL Rewrite rule so that requests from the user agents – ReadyForRequest/1.0+(HealthCheck) & HealthCheck/1.0 are not redirected ?

Currently, I enable Health Check and set the Health Check path to /.

Thanks before for any help.


回答1:


I download offical sample, and make some changes in code, hope it useful to you.

Sample Code --- .net core 3.X(HealthChecksSample)

Method 1.

Because the code is in .net core, I first recommend configuring rewrite in Startup.cs.

public void Configure(IApplicationBuilder app)
{
    app.UseHealthChecks("/");

    app.UseRouting();

    app.MapWhen(
        ctx => ctx.Request.Path.StartsWithSegments("/"),
        appBuilder =>
        {
            appBuilder.UseMiddleware<HealthCheckMiddleware>();
        }
    );

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapHealthChecks("/");

        endpoints.MapGet("/{**path}", async context =>
        {
            await context.Response.WriteAsync(
                "Navigate to /health to see the health status.");
        });
    });
}

It works for me, both in local and azure web app.

I will add Method 2 in your another post.



来源:https://stackoverflow.com/questions/65627278/how-to-fix-warning-application-evaluated-unhealthy-due-to-redirection-on-azu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!