【解決方法】IIS 上の Node.js アプリが再起動後に動作を停止する

プログラミングQA


コマンドプロンプトでアプリの自動インストーラーを作成しようとしています(FUXA: https://github.com/frangoteam/FUXA )。 インストールされているマシンを再起動するまではすべて正常に動作しますが、再起動するとブラウザに次のエラーが表示されます。

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1001
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'.

私が作成したcmdファイル:

 @echo off
 CLS
 ECHO.
 ECHO =============================
 ECHO Running Admin shell
 ECHO =============================

:init
 :: 
 SET installFolder=C:\inetpub\wwwroot\FUXA
 SET rootfuxaFolder=%installFolder%\FUXA
 ::
 setlocal DisableDelayedExpansion
 set cmdInvoke=1
 set winSysFolder=System32
 set "batchPath=%~dpnx0"
 rem this works also from cmd shell, other than %~0
 for %%k in (%0) do set batchName=%%~nk
 set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
 setlocal EnableDelayedExpansion

:checkPrivileges
  NET FILE 1>NUL 2>NUL
  if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
  if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
  ECHO.
  ECHO **************************************
  ECHO Invoking UAC for Privilege Escalation
  ECHO **************************************

  ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
  ECHO args = "ELEV " >> "%vbsGetPrivileges%"
  ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
  ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
  ECHO Next >> "%vbsGetPrivileges%"
  
  if '%cmdInvoke%'=='1' goto InvokeCmd 

  ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
  goto ExecElevation

:InvokeCmd
  ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
  ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"

:ExecElevation
 "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
 exit /B

:gotPrivileges
 setlocal & cd /d %~dp0
 if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)
 

:InstallIIS
 DISM /online /enable-feature /all /featurename:IIS-NetFxExtensibility
 DISM /online /enable-feature /all /featurename:IIS-NetFxExtensibility45
 DISM /online /enable-feature /featurename:IIS-ApplicationInit
 DISM /online /enable-feature /all /featurename:IIS-ASP
 DISM /online /enable-feature /all /featurename:IIS-ASPNET 
 DISM /online /enable-feature /all /featurename:IIS-ASPNET45
 DISM /online /enable-feature /featurename:IIS-ISAPIExtensions
 DISM /online /enable-feature /featurename:IIS-ISAPIFilter
 DISM /online /enable-feature /featurename:IIS-ServerSideIncludes
 DISM /online /enable-feature /featurename:IIS-WebSockets 
 DISM /online /enable-feature /featurename:IIS-WebServer 
 DISM /online /enable-feature /featurename:IIS-WebServerRole     
 
:IISModules
 msiexec.exe /i iisnode-full-v0.2.26-x64.msi
 msiexec.exe /i rewrite_amd64_en-US.msi
 
:InstallNodeJs
 msiexec.exe /i node-v14.21.3-x64.msi
 
:CreateFolderStructure
 MKDIR %rootfuxaFolder%
 
:InstallRootSoftware
 XCOPY /s /y /e %cd%\bin\FUXA\* %rootfuxaFolder%
 
:AddSitesToIIS
 %systemroot%\system32\inetsrv\appcmd add site /name:FUXA /physicalPath:"C:\inetpub\wwwroot\FUXA\FUXA" /bindings:http://*:1881
 
:GrandPermissions
 icacls %rootfuxaFolder% /grant IIS_IUSRS:(OI)(CI)F /T
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 ::START
 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 REM Run shell as admin (example) - put here code as you like
 ::ECHO %batchName% Arguments: P1=%1 P2=%2 P3=%3 P4=%4 P5=%5 P6=%6 P7=%7 P8=%8 P9=%9
 %InstallIIS%
 %IISModules%
 %InstallNodeJs%
 %CreateFolderStructure%
 %InstallRootSoftware%
 %AddSitesToIIS%
 %GrandPermissions%
 start microsoft-edge:http://localhost:1881

編集 :
@Andre Oosthuizenが言ったように、権限を確認しましたが、すべて問題ないと思います。 プロジェクト内に iisnode という名前のフォルダーがあり、その中に 2 つのファイルが含まれていることがわかりました。どちらのファイルにも次の行が含まれています。

2023-05-23T14:07:06.613Z [INF] 	FUXA V.1.1.13-1186-1
2023-05-23T14:07:06.929Z [INF] 	FUXA init in  327ms.
2023-05-23T14:07:06.936Z [INF] 	FUXA started!
2023-05-23T14:07:06.979Z [INF] 	WebServer is running http://127.0.0.1:\\.\pipe\74e72056-19e0-4b2c-bb56-7aa0255adf92/

私が試したこと:

私はこのコードを web.config に入れようとしました:

<configuration>
  <system.webServer>

    <!-- indicates that the hello.js file is a node.js application 
    to be handled by the iisnode module -->

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

    <!-- 
      the iisnode section configures the behavior of the node.js IIS module 
      setting values below are defaults

    * node_env - determines the environment (production, development, staging, ...) in which 
      child node processes run; if nonempty, is propagated to the child node processes as their NODE_ENV
      environment variable; the default is the value of the IIS worker process'es NODE_ENV
      environment variable

    * nodeProcessCommandLine - command line starting the node executable; in shared
      hosting environments this setting would typically be locked at the machine scope.
      
    * interceptor - fully qualified file name of a node.js application that will run instead of an actual application
      the request targets; the fully qualified file name of the actual application file is provided as the first parameter
      to the interceptor application; default interceptor supports iisnode logging
      
    * nodeProcessCountPerApplication - number of node.exe processes that IIS will start per application;
      setting this value to 0 results in creating one node.exe process per each processor on the machine
      
    * maxConcurrentRequestsPerProcess - maximum number of reqeusts one node process can 
      handle at a time
      
    * maxNamedPipeConnectionRetry - number of times IIS will retry to establish a named pipe connection with a
      node process in order to send a new HTTP request
      
    * namedPipeConnectionRetryDelay - delay in milliseconds between connection retries
    
    * maxNamedPipeConnectionPoolSize - maximum number of named pipe connections that will be kept in a connection pool; 
      connection pooling helps improve the performance of applications that process a large number of short lived HTTP requests
      
    * maxNamedPipePooledConnectionAge - age of a pooled connection in milliseconds after which the connection is not reused for
      subsequent requests
    
    * asyncCompletionThreadCount - size of the IO thread pool maintained by the IIS module to process asynchronous IO; setting it
      to 0 (default) results in creating one thread per each processor on the machine
    
    * initialRequestBufferSize - initial size in bytes of a memory buffer allocated for a new HTTP request
    
    * maxRequestBufferSize - maximum size in bytes of a memory buffer allocated per request; this is a hard limit of 
      the serialized form of HTTP request or response headers block
      
    * watchedFiles - semi-colon separated list of files that will be watched for changes; a change to a file causes the application to recycle;
      each entry consists of an optional directory name plus required file name which are relative to the directory where the main application entry point 
      is located; wild cards are allowed in the file name portion only; for example: "*.js;node_modules\foo\lib\options.json;app_data\*.config.json"
      
    * uncFileChangesPollingInterval - applications are recycled when the underlying *.js file is modified; if the file resides
      on a UNC share, the only reliable way to detect such modifications is to periodically poll for them; this setting 
      controls the polling interval
      
    * gracefulShutdownTimeout - when a node.js file is modified, all node processes handling running this application are recycled;
      this setting controls the time (in milliseconds) given for currently active requests to gracefully finish before the 
      process is terminated; during this time, all new requests are already dispatched to a new node process based on the fresh version 
      of the application
    
    * loggingEnabled - controls whether stdout and stderr streams from node processes are captured and made available over HTTP
    
    * logDirectory - directory name relative to the main application file that will store files with stdout and stderr captures; 
      individual log file names have unique file names; log files are created lazily (i.e. when the process actually writes something
      to stdout or stderr); an HTML index of all log files is also maintained as index.html in that directory;
      by default, if your application is at http://foo.com/bar.js, logs will be accessible at http://foo.com/iisnode;
      SECURITY NOTE: if log files contain sensitive information, this setting should be modified to contain enough entropy to be considered
      cryptographically secure; in most situations, a GUID is sufficient
      
    * debuggingEnabled - controls whether the built-in debugger is available
      
    * debuggerPortRange - range of TCP ports that can be used for communication between the node-inspector debugger and the debugee; iisnode
      will round robin through this port range for subsequent debugging sessions and pick the next available (free) port to use from the range
      
    * debuggerPathSegment - URL path segment used to access the built-in node-inspector debugger; given a node.js application at 
      http://foo.com/bar/baz.js, the debugger can be accessed at http://foo.com/bar/baz.js/{debuggerPathSegment}, by default
      http://foo.com/bar/baz.js/debug
    
    * debugHeaderEnabled - boolean indicating whether iisnode should attach the iisnode-debug HTTP response header with 
      diagnostics information to all responses
    
    * maxLogFileSizeInKB - maximum size of a single log file in KB; once a log file exceeds this limit a new log file is created

    * maxTotalLogFileSizeInKB - maximum total size of all log files in the logDirectory; once exceeded, old log files are removed
    
    * maxLogFiles - maximum number of log files in the logDirectory; once exceeded, old log files are removed
    
    * devErrorsEnabled - controls how much information is sent back in the HTTP response to the browser when an error occurrs in iisnode; 
      when true, error conditions in iisnode result in HTTP 200 response with the body containing error details; when false,
      iisnode will return generic HTTP 5xx responses
      
    * flushResponse - controls whether each HTTP response body chunk is immediately flushed by iisnode; flushing each body chunk incurs 
      CPU cost but may improve latency in streaming scenarios
      
    * enableXFF - controls whether iisnode adds or modifies the X-Forwarded-For request HTTP header with the IP address of the remote host
    
    * promoteServerVars - comma delimited list of IIS server variables that will be propagated to the node.exe process in the form of 
      x-iisnode-<server_variable_name> HTTP request headers; for a list of IIS server variables available see 
      http://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx; for example "AUTH_USER,AUTH_TYPE"
      
    * configOverrides - optional file name containing overrides of configuration settings of the iisnode section of web.config; 
      the format of the file is a small subset of YAML: each setting is represented as a <key>: <value> on a separate line 
      and comments start with # until the end of the line, e.g. 
            # This is a sample iisnode.yml file
            nodeProcessCountPerApplication: 2
            maxRequestBufferSize: 8192 # increasing from the default
            # maxConcurrentRequestsPerProcess: 512 - commented out setting
      
    -->

    <iisnode      
      node_env="%node_env%"
      nodeProcessCountPerApplication="1"
      maxConcurrentRequestsPerProcess="1024"
      maxNamedPipeConnectionRetry="100"
      namedPipeConnectionRetryDelay="250"      
      maxNamedPipeConnectionPoolSize="512"
      maxNamedPipePooledConnectionAge="30000"
      asyncCompletionThreadCount="0"
      initialRequestBufferSize="4096"
      maxRequestBufferSize="65536"
      watchedFiles="*.js;iisnode.yml"
      uncFileChangesPollingInterval="5000"      
      gracefulShutdownTimeout="60000"
      loggingEnabled="true"
      logDirectory="iisnode"
      debuggingEnabled="true"
      debugHeaderEnabled="false"
      debuggerPortRange="5058-6058"
      debuggerPathSegment="debug"
      maxLogFileSizeInKB="128"
      maxTotalLogFileSizeInKB="1024"
      maxLogFiles="20"
      devErrorsEnabled="true"
      flushResponse="false"      
      enableXFF="false"
      promoteServerVars=""
      configOverrides="iisnode.yml"
     />

    <!--     
    
    One more setting that can be modified is the path to the node.exe executable and the interceptor:
    
    <iisnode
      nodeProcessCommandLine=""%programfiles%\nodejs\node.exe"" 
      interceptor=""%programfiles%\iisnode\interceptor.js"" />
    
    -->

  </system.webServer>
</configuration>

このコードはここからのものです: https://github.com/Azure/iisnode/blob/master/src/samples/configuration/web.config

解決策 1

以前ここに来たことがありますが、Node.js アプリを実行している IIS アプリ プールのファイル システムのアクセス許可またはログ ファイルの作成が原因のようです。 まだ完了していない場合は、次のことを試してください。

Node.js アプリに割り当てられた IIS アプリ プールの ID に、アプリが配置されているディレクトリへの適切な読み取りおよび書き込みアクセス許可があることを確認します。
a.IISマネージャーを開きます。

b.[アプリケーション プール]セクションを選択し、Node.js アプリに割り当てられたアプリケーション プールを見つけます。

c. アプリケーション プールを右クリックし、[詳細設定]を選択します。

d.[詳細設定]ウィンドウで、[Identity]プロパティを見つけて値 (つまり、ApplicationPoolIdentity、NetworkService など) を確認します。

e. ユーザーまたはアカウントがアプリ ディレクトリ (C:\inetpub\wwwroot\FUXA) に対して必要な権限を持っていることを確認してください。 ユーザーまたはアカウントに読み取りおよび書き込みアクセスを許可する必要がある場合があります。

web.config ファイルでは、logDirectory プロパティが「iisnode」に設定されています。 IIS アプリ プールの ID に、「iisnode」ディレクトリまたは logDirectory プロパティで指定されたディレクトリへの読み取りおよび書き込みアクセス許可があることを確認してください。

詳細なログを有効にしてみてください – web.config ファイルで、 を設定します。 これにより、エラーの詳細が得られ、デバッグが容易になるはずです…

これらのいずれかがあなたの問題の解決に役立つことを願っています。

コメント

タイトルとURLをコピーしました