본문 바로가기
ASP.NET Core

ASP.NET Core 6] Kestrel vs IIS, Hosting Model

by Fastlane 2022. 1. 18.
728x90
반응형

Kestrel

ASP.NET Core를 위한, cross-platform, open-source web server이다. ASP.NET Core에 기본으로 포함되어 있다. 

ASP.NET Core가 지원하는 모든 platforms, versions에서 사용이 가능하다. 

 

Kestrel는 ASP.NET Core application 서비스가 가능하지만, MS는 Apache, IIS, Nginx와 같은 reverse proxy server와 같이 사용하길 권장한다. 

 

.NET Core CLI로 .NET Core application을 실행하면 Kestrel을 웹 서버로 사용한다. 

Window Command Prompt가 실행된다. 

IIS (Internet Information Service)

.NET Core를 IIS에서 돌리기 위해선, Hosting Bundle을 설치해야 한다. 

https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.1-windows-hosting-bundle-installer

 

Download ASP.NET Core 6.0 Runtime (v6.0.1) - Windows Hosting Bundle Installer

 

dotnet.microsoft.com

설치 후에는 server 재시작을 해야한다. 

 

장점

  • 빠르고, 가볍다. 
  • 모든 버전의 .NET Core를 지원한다. 
  • cross-platform

Hosting

1) Out Of Process

<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>

One Web Server(Kestrel) 또는 Two Web Server(external web server(IIS, Nginx, Apache), internal web server(Kestrel))

어떻게 실행하느냐에 따라 external web server를 사용할 수도 안 할 수도 있다. 

.NET Core CLI로 실행을 하면, Kestrel만 web server로 사용된다. 

 

reverse proxy server와 같이 사용할 수도 있다. 단, request를 처리하기 위해서, IIS에서 Kestrel로 2번 요청되어 느리다. 

Kestrel만으로도 web server로 사용이 가능한데, 추가로 reverse proxy server를 사용하는 이유는 아래와 같다. 

  • Security
  • optional additional layer of configuration and defence
  • Load Balancing
  • SSL Setup

2) In Process

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

IIS 내부에서 request를 처리한다.

Only One Web Server(IIS / IIS Express)

Out Of Process보다 빠르다. Kestrel web server를 사용하지 않는다. 

 

.NET Core 버전별로 default process가 다르며, csproj file에서 수정할 수 있다. 

<PropertyGroup>
  <AspNetCoreHostingModel>InProcess/OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>

 

launchSettings.json 의 commandName

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:47301",
      "sslPort": 44371
    }
  },
  "profiles": {
    "Employee": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7215;http://localhost:5215",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

commandName property는 다음 중 하나이다. 

  • Project명
  • IISExpress
  • IIS

이 값은 csproj file의 AspNetCoreHostingModel element값과 함께 앱 실행 시, web server를 어떻게 사용할지 정한다. 

 

commandName AspNetCoreHostingModel Internal Web Server External Web Server
Project Hosting Setting Ignored Only one web server is used - Kestrel
IISExpress InProcess Only one web server is used - IIS Express
IISExpress OutOfProcess Kestrel IIS Express
IIS InProcess Only one web server is used - IIS
IIS OutOfProcess Kestrel IIS

 

Process Name 확인

Program.cs

app.UseEndpoints(endpoints =>
{
    endpoints.MapGet("/", async context =>
    {
        await context.Response.
            WriteAsync(System.Diagnostics.Process.
               GetCurrentProcess().ProcessName);
    });
});

1) Project명 profile로 디버깅을 해보자. 

Kestrel 웹 서버만 사용된다. 

 

2) IIS Express profile로 디버깅 해보자. 

IIS Express만 사용되었다. 

 

3) IIS Express profile에 OutOfProcess 호스팅으로 디버깅 해보자. 

IIS Express - Kestrel이 사용되었다. 

실제 앱을 실행하는 서버는 Kestrel이므로 Project명이 표시된다. 

 

728x90
반응형

댓글