다음을 통해 공유


Getting started with YARP

YARP is designed as a library that provides the core proxy functionality, which you can customize by adding or replacing modules. YARP is currently provided as a NuGet package and code samples. 향후 프로젝트 템플릿 및 미리 빌드된 실행 파일(.exe)을 제공할 계획입니다.

YARP는 .NET Core 인프라를 기반으로 구현되며 Windows, Linux 또는 MacOS에서 사용할 수 있습니다. Microsoft Visual Studio 또는 Visual Studio Code SDK 및 즐겨찾는 편집기를 사용하여 개발을 수행할 수 있습니다.

YARP 2.3.0은 ASP.NET Core 8.0 이상에서 지원합니다.

https://dotnet.microsoft.com/download/dotnet/.NET SDK를 다운로드할 수 있습니다.

새 프로젝트 만들기

아래 단계를 사용하여 빌드된 프로젝트의 전체 버전은 기본 YARP 샘플찾을 수 있습니다.

Start by creating an empty ASP.NET Core application using the command line:

dotnet new web -n MyProxy

또는 Visual Studio 2022에서 새 ASP.NET Core 웹 애플리케이션을 만들고 프로젝트 템플릿에 대해 "비어 있음"을 선택합니다.

패키지 참조 추가

Yarp.ReverseProxy버전 2.3.0 이상에 대한 패키지 참조를 추가합니다.

dotnet add package Yarp.ReverseProxy

메모

.NET 앱에 패키지를 추가하는 방법에 대한 지침은 패키지 설치 및 관리 관련 문서를 확인하거나 패키지 사용 워크플로(NuGet 설명서)에서 참고하세요. 올바른 패키지 버전을 NuGet.org에서 확인하십시오.

YARP 미들웨어 추가

YARP 미들웨어를 사용하도록 Program 파일을 업데이트합니다.

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
var app = builder.Build();
app.MapReverseProxy();
app.Run();

설정

YARP에 대한 구성은 appsettings.json 파일에 정의되어 있습니다. 자세한 내용은 YARP 구성 파일 참조하세요.

구성을 프로그래밍 방식으로 제공할 수도 있습니다. 자세한 내용은 YARP 확장성 구성 공급자참조하세요.

RouteConfigClusterConfig확인하여 사용 가능한 구성 옵션에 대해 자세히 알아봅니다.

{
 "Logging": {
   "LogLevel": {
     "Default": "Information",
     "Microsoft": "Warning",
     "Microsoft.Hosting.Lifetime": "Information"
   }
 },
 "AllowedHosts": "*",
 "ReverseProxy": {
   "Routes": {
     "route1" : {
       "ClusterId": "cluster1",
       "Match": {
         "Path": "{**catch-all}"
       }
     }
   },
   "Clusters": {
     "cluster1": {
       "Destinations": {
         "destination1": {
           "Address": "https://example.com/"
         }
       }
     }
   }
 }
}

프로젝트 실행

When using the .NET CLI, use dotnet run within the sample's directory or dotnet run --project <path to .csproj file>.

In Visual Studio, start the app by clicking the Run button.