.NET Core 2.2/3.0 웹 프로젝트를 IIS에서 호스팅(Inproc, out-of-proc)하는 방법 - AspNetCoreModuleV2 소개
지난 글에서 이미 한번 방법을 설명했는데요.
ASP.NET Core (EXE) 프로세스가 IIS에서 호스팅되는 방법 - ASP.NET Core Module(AspNetCoreModule)
; https://www.sysnet.pe.kr/2/0/11436
어느새 2.2가 나오고는 AspNetCoreModule도 새 버전으로 AspNetCoreModuleV2가 추가되었습니다.
ASP.NET Core In Process Hosting on IIS with ASP.NET Core 2.2
; https://weblog.west-wind.com/posts/2019/Mar/16/ASPNET-Core-Hosting-on-IIS-with-ASPNET-Core-22
Current .NET Core Hosting Bundle installer (direct download)
; https://www.microsoft.com/net/permalink/dotnetcore-current-windows-runtime-bundle-installer
AspNetCoreModuleV2가 내세우는 특장점이라면, 바로 "InProcess" 활성화를 지원한다는 것입니다. 예전에는 w3wp.exe가 단순한 Reverse Proxy로만 동작하고 Kestral 웹 서버에 호스팅 중인 ASP.NET Core 프로세스에서 웹 응용 프로그램이 구동되는 방식이어서 별도의 TCP 소켓 통신이 발생하는 오버헤드가 있었는데요. AspNetCoreModuleV2는 w3wp.exe 프로세스 내부에 ASP.NET Core 웹 응용 프로그램을 직접 로드할 수 있는 모드를 추가함으로써 성능을 더욱 향상시켰다는데 의미가 있습니다.
실제로 간단하게 구성해 볼까요? ^^ 우선, ".NET Core 3" 프로젝트를 생성 후 web.config 파일을 추가하고 AspNetCoreModuleV2 모듈 및 그것이 사용할 설정을 추가합니다.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- To customize the asp.net core module uncomment and edit the following section.
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
이제 "dotnet publish" 명령어로 배포를 하게 되면,
dotnet.exe publish /p:Configuration=Release -r win-x64
".\bin\Release\netcoreapp3.0\win-x64\publish" 하위 폴더에 다음과 같이 web.config이 바뀐 것을 볼 수 있습니다.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- To customize the asp.net core module uncomment and edit the following section.
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Core3Web.exe" arguments="" stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
<!--ProjectGuid: AD6EE067-E62F-4C8F-9590-CBC9CC3A1E50-->
여기까지 했으면 응용 프로그램으로써 할 일은 모두 끝입니다. 남은 작업은 ".\bin\Release\netcoreapp3.0\win-x64\publish" 폴더를 IIS 웹 서버에 복사해 주면 되는데, 이때 해당 웹 서버에는 .NET Core가 설치될 필요는 없지만 "ASP.NET Core/.NET Core: Runtime & Hosting Bundle"은 설치해야 합니다.
Download .NET Core 3.0
; https://dotnet.microsoft.com/download/dotnet-core/3.0
ASP.NET Core/.NET Core: Runtime & Hosting Bundle
; https://dotnet.microsoft.com/download/thank-you/dotnet-runtime-3.0.0-windows-hosting-bundle-installer
끝입니다. 이후 IIS 웹 사이트 설정만 해당 폴더로 연결되어 있으면 웹 브라우저를 통해 ASP.NET Core 웹 응용 프로그램이 w3wp.exe 단독으로 호스팅하는 것을 볼 수 있습니다. (이로 인해 V1 모듈(AspNetCoreModule)에서는 ASPNETCORE_PORT와 같은 환경 변수가 필요했지만 V2에서는 더 이상 사용하지 않게 됩니다.)
물론 이전처럼 분리된 프로세스로 실행하는 것도 가능합니다. 이를 위해 web.config의 hostingModel 옵션만 OutOfProcess로 바꾸면 됩니다.
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
좀 더 자세한 사항은 아래의 공식 문서에서 확인할 수 있습니다.
ASP.NET Core Module
; https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.0
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]