如何解决带有 LetsEncrypt 证书的 Blazor 服务器端由 Certbot
我目前正在开发 Blazor 应用程序(服务器端),我正在考虑为 HTTPS 添加证书。
我已经在我的 Windows Server 上设置了 Certbot 来自动刷新证书,并且已经生成了一个。
但是,我无法告诉 Blazor 使用此证书。
我当前的 appsettings.json
看起来像这样:
{
"Kestrel": {
"Certificates": {
"Default": {
"Path": "C:\\Certbot\\live\\example.com\\fullchain.pem","KeyPath": "C:\\Certbot\\live\\example.com\\privkey.pem"
}
}
}
}
当我使用此配置运行应用程序时,出现 Unspecified error
错误。
我也用 .pfx
文件尝试过,但发生了同样的错误。
我使用的路径是指符号链接,因此我尝试将其更改为直接路径 (C:\\Certbot\\archive\\example.com\\fullchain1.pem
),但随后出现错误 No supported key formats were found. Check that the input represents the contents of a PEM-encoded key file,not the path to such a file. (Parameter 'input')
这个错误让我觉得这是要走的路,因为至少它谈到了关键。但我似乎无法找到丢失此错误的方法。
我考虑可能将 privkey.pem
转换为 private.key
,但根据我的发现,这应该无关紧要。
它似乎确实将其识别为文件,因为一旦我更改它,它就会给我一个 The system cannot find the file specified
错误。
Unspecified error
错误的完整堆栈跟踪:
Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Unspecified error
at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData,String fileName,SafePasswordHandle password,X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName,String password,X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName,String password)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates.CertificateConfigLoader.LoadCertificate(CertificateConfig certInfo,String endpointName)
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application,CancellationToken cancellationToken)
Unhandled exception. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Unspecified error
at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData,X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName,X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName,String password)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates.CertificateConfigLoader.LoadCertificate(CertificateConfig certInfo,String endpointName)
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.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 Application.Program.Main(String[] args) in C:\Application\Program.cs:line 10
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。