【问题标题】:DotNet Linux error - Unable to configure HTTPS endpoint. No server certificate was specifiedDotNet Linux 错误 - 无法配置 HTTPS 端点。未指定服务器证书
【发布时间】:2022-01-01 19:31:53
【问题描述】:

我正在尝试在 Linux 容器上运行 DotNet Core https 服务器。当我尝试在 http 上运行时,没有任何问题。

但是,当我尝试使用 https 运行时,出现以下异常:

    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.
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
Unhandled exception. 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.
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at Chat.Program.Main(String[] args) in C:\Users\localadmin\source\repos\websocket-manager\samples\chat\Program.cs:line 14
Aborted (core dumped)

现在我知道你们中的一些人设法使用Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found 中的命令解决了这个问题,但是我的容器没有安装 dotnet cli(那是因为我不允许安装它),我的应用程序被发布为 Self - 适用于 linux。

我想问你是否有办法解决这个问题,而不必在容器上安装 dotnet?谢谢!

【问题讨论】:

标签: c# .net docker ssl https


【解决方案1】:

你使用 docker image mcr.microsoft.com/dotnet/aspnet:5.0

FROM mcr.microsoft.com/dotnet/aspnet:5.0
COPY . /app
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["dotnet", "dev_ops.dll"]

【讨论】:

    【解决方案2】:

    我认为你应该运行

    dotnet dev-certs https
    

    或者删除 HTTPS 支持 删除代码中的配置功能

    app.UseHttpsRedirection();
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    • 我很确定你的第一个建议不能被 OP 应用,他明确指出他无法访问他试图设置的环境中的 dotnet cli,也无法安装它。第二个可以使用更多细节说明为什么以及在哪些情况下可以接受。
    猜你喜欢
    • 2019-04-17
    • 2020-05-01
    • 2021-10-27
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    • 2015-04-30
    • 2022-01-16
    相关资源
    最近更新 更多