Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)
(시리즈 글이 15개 있습니다.)
오류 유형: 2. [COM+] CreateObject 와 HTTP 500 - Internal server error
; https://www.sysnet.pe.kr/2/0/242

오류 유형: 111. IIS - 500.19 오류 (0x8007000d)
; https://www.sysnet.pe.kr/2/0/976

오류 유형: 201. ASP.NET 웹 사이트를 IIS 7 이상의 환경에서 호스팅할 때 500 오류 발생
; https://www.sysnet.pe.kr/2/0/1563

오류 유형: 219. IIS 500 Internal Server Error - Skydrive에 공유된 경우
; https://www.sysnet.pe.kr/2/0/1612

오류 유형: 232. IIS 500 Internal Server Error - NTFS 암호화된 폴더에 웹 애플리케이션이 위치한 경우
; https://www.sysnet.pe.kr/2/0/1722

오류 유형: 340. HTTP Error 500.23 - Internal Server Error
; https://www.sysnet.pe.kr/2/0/10997

오류 유형: 360. IIS - 500.19 오류 (0x80070021)
; https://www.sysnet.pe.kr/2/0/11061

개발 환경 구성: 307. ASP.NET Core Web Application을 IIS에서 호스팅하는 방법
; https://www.sysnet.pe.kr/2/0/11120

오류 유형: 580. HTTP Error 500.0/500.33 - ANCM In-Process Handler Load Failure
; https://www.sysnet.pe.kr/2/0/12064

오류 유형: 631. .NET Core 웹 응용 프로그램 오류 - HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process
; https://www.sysnet.pe.kr/2/0/12268

오류 유형: 662. ASP.NET Core와 500.19, 500.21 오류 (0x8007000d)
; https://www.sysnet.pe.kr/2/0/12356

개발 환경 구성: 635. 비주얼 스튜디오에서 실행하던 ASP.NET Core (.NET Framework) 응용 프로그램을 명령행에서 실행하는 방법 (2)
; https://www.sysnet.pe.kr/2/0/12955

.NET Framework: 1164. HTTP Error 500.31 - ANCM Failed to Find Native Dependencies
; https://www.sysnet.pe.kr/2/0/12982

오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
; https://www.sysnet.pe.kr/2/0/13488

오류 유형: 899. HTTP Error 500.32 - ANCM Failed to Load dll
; https://www.sysnet.pe.kr/2/0/13579




ASP.NET Core Web Application을 IIS에서 호스팅하는 방법

Visual Studio 2015에서 "ASP.NET Core Web Application(.Net Core)" 프로젝트 템플릿을 선택하고 "Web Application" 유형으로 만들면 기본적인 웹 응용 프로그램이 나옵니다.

빌드하고, IIS 웹 사이트로 연결했는데요. 웹 브라우저로 방문하니 다음과 같은 오류가 발생합니다.

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:

Module
   IIS Web Core 

Notification
   Unknown 

Handler
   Not yet determined 

Error Code
   0x8007000d 

Requested URL
   http://localhost:8087/ 

More Information:
This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error. 

이 오류가 났던 적이 있었군요. ^^

IIS - 500.19 오류 (0x8007000d)
; https://www.sysnet.pe.kr/2/0/976

즉, web.config 파일에 지정된 모듈이 인식되지 않았던 것인데요. 실제로 asp.net core 웹 응용 프로그램의 기본 web.config 파일을 보면,

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>

AspNetCoreModule 모듈이 지정된 것을 볼 수 있습니다. 당연히 기본 설치된 Windows Server에는 관련 모듈이 없습니다. 따라서, IIS에서 .NET Core를 호스팅 할 수 있도록 부가 작업을 해야 합니다.

Install the .NET Core Windows Server Hosting bundle
; https://learn.microsoft.com/en-us/aspnet/core/publishing/iis

위의 글에 나온 것처럼, ".NET Core Windows Server Hosting bundle"을 설치하면 되는데요.

.NET Core Windows Server Hosting bundle (DotNetCore.1.1.0-WindowsHosting.exe)
; https://download.microsoft.com/download/F/6/E/F6ECBBCC-B02F-424E-8E03-D47E9FA631B7/DotNetCore.1.1.0-WindowsHosting.exe

위의 설치 파일은 ".NET Core Runtime"과 ".NET Core Library" 및 IIS에서 요청을 처리하는 ASP.NET Core 모듈을 설치합니다. 그런데, 이런 상태에서도 다음과 같은 오류를 내면서 실행이 안됩니다.

HTTP Error 502.5 - Process Failure 

Common causes of this issue: 
* The application process failed to start 
* The application process started but then stopped 
* The application process started but failed to listen on the configured port 

Troubleshooting steps: 
* Check the system event log for error messages 
* Enable logging the application process’ stdout messages 
* Attach a debugger to the application process and inspect 

이때의 이벤트 로그를 보면 다음과 같은 항목이 보입니다.

Log Name:      Application
Source:        IIS AspNetCore Module
Date:          2016-12-25 오후 8:27:18
Event ID:      1000
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      TESTPC
Description:
Application 'MACHINE/WEBROOT/APPHOST/COREWEBAPP' with physical root 'D:\temp\coreapp\' failed to start process with commandline '"%LAUNCHER_PATH%" %LAUNCHER_ARGS%', ErrorCode = '0x80070002 : 0.

보아하니, 이것은 web.config의 설정값입니다.

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>

이 설정으로 검색해 보면,

ASP.Net Core 1.0 RC2 : What are LAUNCHER_PATH and LAUNCHER_ARGS mentioned in web.config?
; http://stackoverflow.com/questions/37463186/asp-net-core-1-0-rc2-what-are-launcher-path-and-launcher-args-mentioned-in-web

web.config에 저런 식으로 processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%"로 설정된 것은 Visual Studio 내에서만 유효한 것입니다. 따라서, Visual Studio에서 개발할 때는 저 설정으로 빌드/실행하는 것은 가능하지만 IIS 웹 서버로 배포할 때는 그에 맞게 web.config이 변경되어야 합니다. 바로 이 작업을, Visual Studio의 "Publish" 명령으로 하는 것입니다.

이를 위해, Visual Studio에서 해당 Core 웹 프로젝트를 우 클릭한 후 "Publish..." 메뉴를 선택해 줍니다.

aspnet_core_on_iis_1.png

그럼 배포(Publish) 마법사가 뜨는데, "Custom" 항목을 선택하고 뜨는 "New Custom Profile" 창에서 배포 설정을 특정할 이름을 (원하는 대로) 지정해 줍니다. (이 배포 이름으로 저장된 설정은 나중에 재사용이 가능합니다.)

aspnet_core_on_iis_2.png

그다음 배포 경로를 지정하고, (아래의 화면에서는 기본값 그대로 "/bin/Release/PublishOutput")

aspnet_core_on_iis_3.png

마지막 배포 설정을 명시해주고 "Publish" 버튼을 눌러주면,

aspnet_core_on_iis_4.png

./bin/Release/PublishOutput 폴더에 실제 IIS 웹 서버에 배포할 바이너리 이미지들이 생성됩니다. 이렇게 배포된 PublishOutput 폴더의 web.config을 보면 다음과 같은 내용을 담고 있습니다.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\WebApplication1.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
  </system.webServer>
</configuration>
<!--ProjectGuid: 028962a2-4bfe-4352-8f7d-6ee7fb543516-->

보시는 것처럼 processPath가 "%LAUNCHER_PATH%"에서 "dotnet"으로, arguments는 "%LAUNCHER_ARGS%"에서 ".\WebApplication1.dll"로 바뀌었습니다. 이렇게 바뀌어야 정상적으로 IIS에서 ASP.NET Core Web Application이 동작합니다.



그러니까, 결국 IIS에서의 ASP.NET Core 웹 응용 프로그램 실행은 다음과 같은 구조를 갖게 됩니다.

aspnet_core_on_iis_5.png

재미있는 것은, 요청을 AspNetCoreModule의 handler에서 받기 때문에 요청까지는 IIS의 관리를 받는다는 것입니다. 이로 인해 "Web Garden"을 2개 이상으로 지정해도 동일한 w3wp.exe가 2개 뜨고 그 각각의 하위에 다시 dotnet.exe가 자식 프로세스로 연결됩니다. 물론, 포트 충돌 문제는 없습니다. 이때의 dotnet.exe에 있는 ASP.NET Core 웹 응용 프로그램은 포트를 점유하지 않고 요청만 처리해 주는 별도 프로세스로 동작하는 것뿐입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 8/10/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [46]  47  48  49  50  51  52  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12478정성태1/5/202111262.NET Framework: 997. C# - ArrayPool<T> 소개파일 다운로드1
12477정성태1/5/202113636기타: 79. github 코드 검색 방법 [1]
12476정성태1/5/202110308.NET Framework: 996. C# - 닷넷 코어에서 다른 스레드의 callstack을 구하는 방법파일 다운로드1
12475정성태1/5/202112894.NET Framework: 995. C# - Span<T>와 Memory<T> [1]파일 다운로드1
12474정성태1/4/202110416.NET Framework: 994. C# - (.NET Core 2.2부터 가능한) 프로세스 내부에서 CLR ETW 이벤트 수신 [1]파일 다운로드1
12473정성태1/4/20219229.NET Framework: 993. .NET 런타임에 따라 달라지는 정적 필드의 초기화 유무 [1]파일 다운로드1
12472정성태1/3/20219509디버깅 기술: 178. windbg - 디버그 시작 시 스크립트 실행
12471정성태1/1/202110001.NET Framework: 992. C# - .NET Core 3.0 이상부터 제공하는 runtimeOptions의 rollForward 옵션 [1]
12470정성태12/30/202010163.NET Framework: 991. .NET 5 응용 프로그램에서 WinRT API 호출 [1]파일 다운로드1
12469정성태12/30/202013761.NET Framework: 990. C# - SendInput Win32 API를 이용한 가상 키보드/마우스 [1]파일 다운로드1
12468정성태12/30/202010379Windows: 186. CMD Shell의 "Defaults"와 "Properties"에서 폰트 정보가 다른 문제 [1]
12467정성태12/29/202010277.NET Framework: 989. HttpContextAccessor를 통해 이해하는 AsyncLocal<T> [1]파일 다운로드1
12466정성태12/29/20208264.NET Framework: 988. C# - 지연 실행이 꼭 필요한 상황이 아니라면 singleton 패턴에서 DCLP보다는 static 초기화를 권장파일 다운로드1
12465정성태12/29/202011392.NET Framework: 987. .NET Profiler - FunctionID와 연관된 ClassID를 구할 수 없는 문제
12464정성태12/29/202010243.NET Framework: 986. pptfont.exe - PPT 파일에 숨겨진 폰트 설정을 일괄 삭제
12463정성태12/29/20209294개발 환경 구성: 520. RDP(mstsc.exe)의 다중 모니터 옵션 /multimon, /span
12462정성태12/27/202010921디버깅 기술: 177. windbg - (ASP.NET 환경에서 유용한) netext 확장
12461정성태12/21/202011754.NET Framework: 985. .NET 코드 리뷰 팁 [3]
12460정성태12/18/20209449기타: 78. 도서 소개 - C#으로 배우는 암호학
12459정성태12/16/20209850Linux: 35. C# - 리눅스 환경에서 클라이언트 소켓의 ephemeral port 재사용파일 다운로드1
12458정성태12/16/20209344오류 유형: 694. C# - Task.Start 메서드 호출 시 "System.InvalidOperationException: 'Start may not be called on a task that has completed.'" 예외 발생 [1]
12457정성태12/15/20208899Windows: 185. C# - Windows 10/2019부터 추가된 SIO_TCP_INFO파일 다운로드1
12456정성태12/15/20209179VS.NET IDE: 156. Visual Studio - "Migrate packages.config to PackageReference"
12455정성태12/15/20208697오류 유형: 693. DLL 로딩 시 0x800704ec - This Program is Blocked by Group Policy
12454정성태12/15/20209273Windows: 184. Windows - AppLocker의 "DLL Rules"를 이용해 임의 경로에 설치한 DLL의 로딩을 막는 방법 [1]
12453정성태12/14/202010244.NET Framework: 984. C# - bool / BOOL / VARIANT_BOOL에 대한 Interop [1]파일 다운로드1
... [46]  47  48  49  50  51  52  53  54  55  56  57  58  59  60  ...