簡體   English   中英

ASP.NET 7 Blazor 服務器 - Linux 主機的 Certbot SSL

[英]ASP.NET 7 Blazor Server - Certbot SSL for Linux Host

我最近在 Debian 11 服務器上啟動了一個 Blazor 服務器應用程序。 該應用程序通過 Linux Docker 容器運行。 我已經使用 DNS 將我的域名連接到我的服務器,並且正在嘗試為我的 Blazor 應用程序獲取應用於我的域的 SSL 證書。

通過遵循 Certbot 指南,我在我的 Debian 11 服務器上完成了以下操作,其中我的 Blazor 容器托管到端口 80: apt-get install cerbot certbot certonly --standalone我收到以下消息:

Congratulations!
Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem

我的網站仍然沒有使用 https。從這一點上我找不到任何其他說明來應用 SSL。 我是否需要向我的 Blazor 服務器應用程序添加代碼以指向 SSL 文件? 我是否需要將 SSL 文件掛載到我的 Docker 容器中的某個位置? 謝謝。

更新:我一直在使用以下命令運行我的 Docker 容器。 我已經測試了我的 keys 文件夾的安裝並且可以看到它是正確的,但是我在啟動容器時仍然遇到問題。 它似乎無法找到密鑰,即使它們已正確安裝到容器中: docker run -p 80:80 -p 443:443 -v /etc/letsencrypt/live/example.com:/https/ -e AS.NETCORE_URLS="https://+;http://+" -e AS.NETCORE_HTTPS_PORT=443 -e AS.NETCORE_Kestrel__Certificates__Default__Path=/https/fullchain.pem -e AS.NETCORE_Kestrel__Certificates__Default__KeyPath=/https/privkey.pem --restart always --name blazorserver blazorserver:1.01

我收到這些終端錯誤,導致 Program.cs 無法運行 app.Run();

warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
      Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {c9ce4f00-c893-456c-b894-6421bf21ffd8} may be persisted to storage in unencrypted form.
Unhandled exception. System.IO.FileNotFoundException: Could not find file '/https/fullchain.pem'.
File name: '/https/fullchain.pem'
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Func`4 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Func`4 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.File.ReadAllText(String path, Encoding encoding)
   at System.Security.Cryptography.X509Certificates.X509Certificate2Collection.ImportFromPemFile(String certPemFilePath)
   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 Program.<Main>$(String[] args) in /src/Program.cs:line 36

因此,問題是 /etc/letsencrypt/live/example.com/fullchain.pem 文件需要訪問 /etc/letsencrypt 層次結構中的其他文件。 將整個 /etc/letsencrypt 目錄掛載到 /https 后,我能夠使用完整路徑訪問 SSL 文件,例如 __Path 變量的 /https/live/example.com/fullchain.pem。

希望有人發現我的故障排除有用,因為我找不到太多關於 Let's Encrypt SSL setup for Kestrel 和/或 Blazor 的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM