Linux 个容器上的 Kestrel 证书 "no such file" 在 Windows 个容器上工作

Kestrel Certificate "no such file" on Linux containers works find on Windows containers

我已经在 docker windows 容器上使用 https 构建了一个没有问题的 aspnetcore webapp。当我使用 http 在 Linux 容器上将其修改为 运行 时,没有问题。

但是,当我在 Linux 容器上启用 https 时,kestrel 会抛出一个异常,提示 "no file found" 证书。搜索后我在 https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/aspnetcore-docker-https-development.md

找到了
Note: The certificate name, in this case aspnetapp.pfx must match the project assembly name.

我重命名了证书以与程序集名称完全匹配。

假设名字是:

Company.RLG.Server.WebAPI.dll

我将证书文件命名为:"Company.RLG.Server.WebAPI.pfx"。出于我的测试应用程序的目的,我只是将其复制到 /https 文件夹。 (后面会做分卷。)

我的 Kestrel 环境变量的 DockerFile 部分是:

ENV ASPNETCORE_HTTPS_PORT="8001"
ENV ASPNETCORE_Kestrel__Certificates__Default__Password="x"
ENV ASPNETCORE_Kestrel__Certificates__Default__Path="\https\Company.RLG.Server.WebAPI.pfx"
ENV ASPNETCORE_URLS="https://+;http://+"

然而,即使如此重命名,Kestrel 仍抱怨道:

crit: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to start Kestrel.
Interop+Crypto+OpenSslCryptographicException: error:2006D080:BIO routines:BIO_new_file:no such file
   at Interop.Crypto.CheckValidOpenSslHandle(SafeHandle handle)
   at Internal.Cryptography.Pal.CertificatePal.FromFile(String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)

搜索并发现了很多与此问题相似但不完全相同的变体,其中 none 似乎适用于我的情况。

欢迎提问、建议和回答。

呃。

抱歉,各位,愚蠢的问题。我发现了这个问题。

你在上面看到我在证书的路径中加入了反斜杠。

我将它们更改为正斜杠,现在一切正常。