독까의 이야기

IIS + node.js  환경을 구축하였다. 


진행하면서 확인 된 사항들에 대해 기록을 한다. 



node.js 프로그램은 공식 홈페이지에서 다운 받으면 된다. 


https://nodejs.org/ko/



iisnode 모듈은 github 에서 다운 받으면 된다.


https://github.com/tjanczuk/iisnode/wiki/iisnode-releases


두 개 다 default 로 설치를 진행 하면 된다. 



필수로 구축되어 있어야 하는 사항에 대해 확인 한다. 



1.  웹폴더가 등록 된 파티션에 Users 의 "읽기" 권한이 할당되어 있어야 한다. 없을시 아래와 같은 오류 출력 된다. 


Application has thrown an uncaught exception and is terminated:
Error: EPERM: operation not permitted, lstat 'd:\'
    at Object.realpathSync (fs.js:1617:13)
    at toRealPath (module.js:164:13)
    at Function.Module._findPath (module.js:213:22)
    at Function.Module._resolveFilename (module.js:545:25)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Program Files (x86)\iisnode\interceptor.js:210:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)






2.  해당 웹사이트의 web.config 에 구문 추가가 필요하다. 


        <handlers>
            <add name="iisnode" path="*.js" verb="*" modules="iisnode" resourceType="File" />
        </handlers>


만약 구문을 추가 했는데, 아래와 같은 오류가 출력 된다면 구문을 한 줄 더 추가 한다. (x64 버전 설치시에만)


The iisnode module is unable to start the node.exe process. Make sure the node.exe executable is available at the location specified in the system.webServer/iisnode/@nodeProcessCommandLine element of web.config. By default node.exe is expected in one of the directories listed in the PATH environment variable.


 <iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade" nodeProcessCommandLine="\program files\nodejs\node.exe"/>



3.  iisnode 폴더가 웹사이트 루트 디렉토리에 생성되어 있어야 한다. 폴더가 없거나 생성 할 수 있는 권한이 없을 시에는 아래와 같은 오류 출력 된다. 


iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1002
HTTP reason: Internal Server Error

You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'.
In addition to the log of stdout and stderr of the node.exe process, consider using debugging and ETW traces to further diagnose the problem.
The node.exe process has not written any information to stderr or iisnode was unable to capture this information. Frequent reason is that the iisnode module is unable to create a log file to capture stdout and stderr output from node.exe. Please check that the identity of the IIS application pool running the node.js application has read and write access permissions to the directory on the server where the node.js application is located. Alternatively you can disable logging by setting system.webServer/iisnode/@loggingEnabled element of web.config to 'false'. 


루트 디렉토리에 응용프로그램풀 계정을 쓰기 및 삭제 권한 포함하여 할당하면, 자동으로 iisnode 폴더를 생성하고, 로그 기록 및 삭제 해준다.


또는 iisnode 폴더를 생성하고, 해당 폴더에 응용프로그램풀 계정을 쓰기 및 삭제 권한 포함하여 할당하면 로그 기록 및 삭제 가능하다. 




쓰기 권한이 할당 된 폴더는 반드시 처리기 매핑에서 스크립트 사용 권한을 제거해야 한다. 


보안 침해로 인해 웹쉘 업로드 및 스크립트 실행으로 인해 서버 권한 탈취 가능성을 방지해야 한다.