'.NET Core throws Kestrel error on startup when using Azure Container Instances, Caddy

I'm fumbling through my first exploration into docker containers with .NET. My local development environment is good to go - I've got my dev certs created and specified in my configuration file.

However, I'm trying to deploy to Azure Container Instances using a Caddy sidecar as a reverse-proxy. My application container fails on startup with the error: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

As far as I understand, I'll still need Kestrel, however the incoming traffic is no longer required to be HTTPS since it's being routed internally through the reverse-proxy.

I've tried tampering with my Startup.cs and Program.cs files to no avail. Can anyone point me in the right direction? Thanks.

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddMvc(options => { options.EnableEndpointRouting = false; });
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app
      .UseStaticFiles()
      .UseHsts()
      .UseHttpsRedirection()
      .UseMvc(routes => routes.MapRoute(name: "default", template: "{controller=App}/{action=Index}/{id?}"));
}

Program.cs

public static void Main(string[] args)
{
    CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
      .ConfigureWebHostDefaults(webBuilder =>
      {
          webBuilder.UseStartup<Startup>();
          webBuilder.UseKestrel();
      })
      .ConfigureAppConfiguration(cb => { cb.AddEnvironmentVariables(); });


Solution 1:[1]

When the developer certs seems to had expired, you can try running these but initially Close your browsers so that they do not cache the certificates

On the commandline run

  1. dotnet dev-certs https –clean

  2. then run dotnet dev-certs https -t a single time to create and trust a new development certificate.

  3. Then please check the certificate with dotnet dev-certs https –verbose

  4. and Restart VS

Reference: Unable to configure HTTPS endpoint- Wayne Thompson

You can try removing app.UseHttpsRedirection(); and adding UseHsts() as the way as you mentioned .

References:

  1. Also please check this SO reference where kestrel configuration with urls is made.

  2. docker - Unable to configure HTTPS endpoint for .net Core Kestral Server in Linux Container on Azure - Stack Overflow

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kavyasaraboju-MT