次の方法で共有


YARP Lets Encrypt

この記事で説明するLettuceEncrypt NuGet パッケージはアーカイブされ、サポートされなくなったため、パッケージの使用はお勧めしません。

紹介

YARP では、別の ASP.NET Core プロジェクトの API () を使用して、証明機関 LettuceEncrypt をサポートできます。 これにより、最小限の構成でクライアントと YARP の間に TLS を設定できます。

必要条件

LettuceEncrypt パッケージの依存関係を追加します。

<PackageReference Include="LettuceEncrypt" Version="1.1.2" />

構成

設定する必要がある LettuceEncrypt に必要なオプションがあります。 appsettings.jsonの例を参照してください。

{
  "Urls": "http://*:80;https://*:443",

  "Logging": { ... },

  "ReverseProxy": {
    "Routes": { ... },
    "Clusters": { ... }
  },

  "LettuceEncrypt": {
    // Set this to automatically accept the terms of service of your certificate 
    // authority.
    // If you don't set this in config, you will need to press "y" whenever the 
    // application starts
    "AcceptTermsOfService": true,

    // You must specify at least one domain name
    "DomainNames": [ "example.com" ],

    // You must specify an email address to register with the certificate authority
    "EmailAddress": "it-admin@example.com"
  }
}

サービスの更新

services.AddLettuceEncrypt();

その他のオプション (証明書の保存など) については、 LettuceEncrypt プロジェクト README の例を参照してください。

Kestrel エンドポイント

プロジェクトで オプションを使用して IP アドレス、ポート、または HTTPS 設定を明示的に構成している場合は、を呼び出します。

例:

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(kestrel =>
{
    kestrel.ListenAnyIP(443, portOptions =>
    {
        portOptions.UseHttps(h =>
        {
            h.UseLettuceEncrypt(kestrel.ApplicationServices);
        });
    });
});