-1

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(); });
Santi
  • 416
  • 4
  • 21
  • try taking out the 'usehttpsredirection' – pm100 Apr 29 '22 at 01:04
  • @pm100 My latest attempt was removing `UseHttpsRedirection()`, `UseHsts()`, and updating my Dockerfile to remove any specified HTTPS ports. The site now loads properly. I'm going to put each thing back one-by-one and see what I can keep versus what is getting in the way. Thank you! – Santi Apr 29 '22 at 01:54

1 Answers1

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

kavyaS
  • 8,026
  • 1
  • 7
  • 19