HttpPlatformHandler 構成リファレンス

IIS チーム別

この記事では、HttpPlatformHandler の概要と、モジュールの構成について説明します。

機能の概要

HttpPlatformHandler は IIS 8 以降の IIS モジュールであり、次の 2 つの処理を行います。

  1. http リスナーのプロセス管理 - これは、http 要求のポートでリッスンできる任意のプロセスである可能性があります。 たとえば、Tomcat、Jetty、Node.exe、Ruby などです。
  2. プロキシは、管理するプロセスに対して要求を送信します。

HttpPlatformHandler の構成

HttpPlatformHandler は、サイトまたはアプリケーション web.config ファイルを介して構成され、system.webServer - httpPlatform 内に独自の構成セクションがあります。

構成属性

属性 説明
processPath 必須の属性。 HTTP 要求をリッスンするプロセスを起動する実行可能ファイルまたはスクリプトへのパス。 v1.2 の相対パスがサポートされている時点で、パスが '.' で始まる場合、パスはサイト ルートに対する相対パスと見なされます。 既定値はありません
arguments 省略可能な文字列値。 processPath 設定で指定された実行可能ファイルまたはスクリプトの引数。 既定値はありません。
startupTimeLimit 省略可能な整数属性 HttpPlatformHandler が実行可能ファイル/スクリプトがポートでリッスンしているプロセスを開始するまで待機する時間 (秒単位)。 この時間制限を超えた場合、HttpPlatformHandler はプロセスを強制終了し、 startupRetryCount 回再度起動しようとします。 既定値は 10 です。
startupRetryCount 省略可能な整数属性 HttpPlatformHandler が processPath で指定されたプロセスの起動を試行する回数。 詳細については、 startupTimeLimit を参照してください。 既定値は 10 です。
rapidFailsPerMinute 省略可能な整数属性 processPath で指定されているプロセスが 1 分間にクラッシュできる回数を指定します。 この制限を超えた場合、 HttpPlatformHandler は残りの分の間、プロセスの起動を停止します。 managedPipelineMode 属性には、次のいずれかの値を指定できます。 既定値は、10 です。
requestTimeout 省略可能な期間属性。 HttpPlatformHandler%HTTP_PLATFORM_PORT% で待機しているプロセスからの応答を待つ時間を指定します。 既定値は "00:02:00" です。
stdoutLogEnabled 省略可能なブール値属性。 true の場合、processPath 設定で指定されたプロセスの stdoutstderrstdoutLogFile で指定されたファイルにリダイレクトされます。既定値は false です。
stdoutLogFile 省略可能な文字列属性。 processPath で指定されたプロセスからの stdoutstderr がログに記録される相対 OR 絶対ファイル パスを指定します。 相対パスはサイトのルートに対するものです。 v1.2 以降、'.' で始まるパスはサイト ルートに対して相対的になり、他のすべてのパスは絶対パスとして扱われます。 既定値は httpplatform-stdout.
processesPerApplication 省略可能な整数属性 アプリケーションごとにスピンアップできる processPath 設定で指定されたプロセスのインスタンスの数を指定します。 最大値は 100 です。 既定値は 1 です。
forwardWindowsAuthToken True または False です。 v1.2 の新機能。 この設定が true に設定されている場合、トークンは要求ごとにヘッダー 'X-IIS-WindowsAuthToken' として %HTTP_PLATFORM_PORT% をリッスンしている子プロセスに転送されます。 要求ごとにこのトークンで CloseHandle を呼び出すのは、そのプロセスの役割です。 既定値は false です。

子要素

Element 説明
environmentVariables processPath 設定で指定されたプロセスの environmentVariables コレクションを構成します。
recycleOnFileChange は、指定されたリスト内の ファイル に変更が加えられたときにワーカー プロセスをリサイクルするファイル コレクションを構成します。 要素の構文 (例: <file path="\touch.txt"/> または <file path="c:\file.txt"/>

HttpPlatformHandler の構成例

さまざまなプロセスで多数のアプリケーションを実行するための構成例を次に示します。

Tomcat

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="c:\dev\javasites\bin\apache-tomcat-8.0.15\bin\startup.bat" 
                  arguments="" 
                  stdoutLogEnabled="true" 
                  stdoutLogFile="\\?c:\dev\javasites\log.txt">
      <environmentVariables>
        <environmentVariable name="JRE_HOME" value="%programfiles%\java\jdk1.8.0_25" />
        <environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT% -Dsomeotherconfig=value"/>
        <environmentVariable name="CATALINA_HOME" value="c:\dev\javasites\bin\apache-tomcat-8.0.15" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

桟橋

<?xml version="1.0"?>
<configuration>
    <system.webServer>
      <handlers>
        <add name="httpplatformhandler" path="*" verb="*" modules ="httpPlatformHandler" resourceType="Unspecified"/>
      </handlers>
      <httpPlatform processPath="c:\Program Files\Java\jdk1.8.0_25\bin\java.exe" 
                    arguments="-Djava.net.preferIPv4Stack=true -Djetty.port=%HTTP_PLATFORM_PORT% -Djetty.base=&quot;c:\dev\javasites\bin\jetty-distribution-9.2.6.v20141205&quot; -jar &quot;c:\dev\javasites\bin\jetty-distribution-9.2.6.v20141205\start.jar&quot;" 
                    startupTimeLimit="20" 
                    startupRetryCount="20" 
                    stdoutLogEnabled="true"></httpPlatform>
    </system.webServer>
</configuration>

サンプル コード

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample {

    private static void Main() {
        
        using(ServerManager serverManager = new ServerManager()) { 
            Configuration config = serverManager.GetWebConfiguration("JavaSites");
            
            ConfigurationSection httpPlatformSection = config.GetSection("system.webServer/httpPlatform");
            httpPlatformSection["processPath"] = @"c:\dev\javasites\bin\apache-tomcat-8.0.15\bin\startup.bat";
            httpPlatformSection["arguments"] = @"";
            httpPlatformSection["stdoutLogFile"] = @"=""\\?c:\dev\javasites\log.txt";
            
            ConfigurationElementCollection environmentVariablesCollection = httpPlatformSection.GetCollection("environmentVariables");
            
            ConfigurationElement environmentVariableElement = environmentVariablesCollection.CreateElement("environmentVariable");
            environmentVariableElement["name"] = @"JRE_HOME";
            environmentVariableElement["value"] = @"=""%programfiles%\java\jdk1.8.0_25";
            environmentVariablesCollection.Add(environmentVariableElement);
            
            ConfigurationElement environmentVariableElement1 = environmentVariablesCollection.CreateElement("environmentVariable");
            environmentVariableElement1["name"] = @"CATALINA_OPTS";
            environmentVariableElement1["value"] = @"=""-Dport.http=%HTTP_PLATFORM_PORT% -Dsomeotherconfig=value";
            environmentVariablesCollection.Add(environmentVariableElement1);
            
            ConfigurationElement environmentVariableElement2 = environmentVariablesCollection.CreateElement("environmentVariable");
            environmentVariableElement2["name"] = @"CATALINA_HOME";
            environmentVariableElement2["value"] = @"c:\dev\javasites\bin\apache-tomcat-8.0.15";
            environmentVariablesCollection.Add(environmentVariableElement2);
            
            serverManager.CommitChanges();
        }
    }
}

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/JavaSites";

var httpPlatformSection = adminManager.GetAdminSection("system.webServer/httpPlatform", "MACHINE/WEBROOT/APPHOST/JavaSites");
httpPlatformSection.Properties.Item("processPath").Value = "c:\\dev\\javasites\\bin\\apache-tomcat-8.0.15\\bin\\startup.bat";
httpPlatformSection.Properties.Item("arguments").Value = "";
httpPlatformSection.Properties.Item("stdoutLogFile").Value = "=\"\\\\?c:\\dev\\javasites\\log.txt";

var environmentVariablesCollection = httpPlatformSection.ChildElements.Item("environmentVariables").Collection;

var environmentVariableElement = environmentVariablesCollection.CreateNewElement("environmentVariable");
environmentVariableElement.Properties.Item("name").Value = "JRE_HOME";
environmentVariableElement.Properties.Item("value").Value = "=\"%programfiles%\\java\\jdk1.8.0_25";
environmentVariablesCollection.AddElement(environmentVariableElement);

var environmentVariableElement1 = environmentVariablesCollection.CreateNewElement("environmentVariable");
environmentVariableElement1.Properties.Item("name").Value = "CATALINA_OPTS";
environmentVariableElement1.Properties.Item("value").Value = "=\"-Dport.http=%HTTP_PLATFORM_PORT% -Dsomeotherconfig=value";
environmentVariablesCollection.AddElement(environmentVariableElement1);

var environmentVariableElement2 = environmentVariablesCollection.CreateNewElement("environmentVariable");
environmentVariableElement2.Properties.Item("name").Value = "CATALINA_HOME";
environmentVariableElement2.Properties.Item("value").Value = "c:\\dev\\javasites\\bin\\apache-tomcat-8.0.15";
environmentVariablesCollection.AddElement(environmentVariableElement2);

adminManager.CommitChanges();

コマンド ライン (AppCmd)

appcmd.exe set config "JavaSites" -section:system.webServer/httpPlatform /processPath:"c:\dev\javasites\bin\apache-tomcat-8.0.15\bin\startup.bat" /arguments:"" /stdoutLogFile:"="""\\?c:\dev\javasites\log.txt"  

appcmd.exe set config "JavaSites" -section:system.webServer/httpPlatform /+"environmentVariables.[name='JRE_HOME',value='="""%programfiles%\java\jdk1.8.0_25']" 

appcmd.exe set config "JavaSites" -section:system.webServer/httpPlatform /+"environmentVariables.[name='CATALINA_OPTS',value='="""-Dport.http=%HTTP_PLATFORM_PORT% -Dsomeotherconfig=value']" 

appcmd.exe set config "JavaSites" -section:system.webServer/httpPlatform /+"environmentVariables.[name='CATALINA_HOME',value='c:\dev\javasites\bin\apache-tomcat-8.0.15']"

PowerShell

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/JavaSites'  -filter "system.webServer/httpPlatform" -name "processPath" -value "c:\dev\javasites\bin\apache-tomcat-8.0.15\bin\startup.bat"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/JavaSites'  -filter "system.webServer/httpPlatform" -name "arguments" -value ""
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/JavaSites'  -filter "system.webServer/httpPlatform" -name "stdoutLogFile" -value "="""\\?c:\dev\javasites\log.txt"

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/JavaSites'  -filter "system.webServer/httpPlatform/environmentVariables" -name "." -value @{name='JRE_HOME';value='="""%programfiles%\java\jdk1.8.0_25'}

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/JavaSites'  -filter "system.webServer/httpPlatform/environmentVariables" -name "." -value @{name='CATALINA_OPTS';value='="""-Dport.http=%HTTP_PLATFORM_PORT% -Dsomeotherconfig=value'}

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/JavaSites'  -filter "system.webServer/httpPlatform/environmentVariables" -name "." -value @{name='CATALINA_HOME';value='c:\dev\javasites\bin\apache-tomcat-8.0.15'}