Search code examples
windowsapacheasp.net-coressl-certificatekestrel

Why does Kestrel fail to start when certificates are present?


I have Apache 2.4 as a reverse proxy with Kestrel on Windows Server 2019. I have one app already running on the server. I set up a second app with its own appname.conf file in C:\Apache24\conf\sites-enabled and added new, unexpired SSL certificate files to C:\Apache24\conf\ssl\appname.

In the app's Program.cs, this is the CreateHostBuilder, where I've specified the ports to be used so they are different from the first app's:

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseUrls("http://localhost:5002", "https://localhost:5003");
                webBuilder.UseStartup<Startup>();
            });

When running the command to start the app on the server (dotnet appname.dll), I get this error:

crit: Microsoft.AspNetCore.Server.Kestrel[0] Unable to start Kestrel. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'. For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.

Even though I have the real SSL certificates, I've run dotnet dev-certs https --trust, as the error suggests, even going as far as deleting the certs from the Windows cert manager GUI first, as suggested on Github, to no avail.

Any help is greatly appreciated.


Solution

  • As pointed out in the comments by Lex Li, UseUrls() doesn't need an https version of the URL. To have additional apps on the same server, only an unused port needs to be provided to Kestrel, and this is how it's done. Here is how CreateHostBuilder should look:

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseUrls("http://localhost:5002");
                webBuilder.UseStartup<Startup>();
            });