Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
di IIS Team
Questo articolo offre una panoramica di HttpPlatformHandler e illustra la configurazione del modulo.
Panoramica delle funzionalità
HttpPlatformHandler è un modulo IIS, per IIS 8+, che esegue le due operazioni seguenti:
- Gestione dei processi dei listener HTTP: può trattarsi di qualsiasi processo in grado di restare in ascolto su una porta per le richieste HTTP. Ad esempio, Tomcat, Jetty, Node.exe, Ruby e così via;
- Il proxy inoltra le richieste al processo che gestisce.
Configurazione di HttpPlatformHandler
HttpPlatformHandler viene configurato tramite i file web.config di un sito o di applicazioni e ha una propria sezione di configurazione all'interno di system.webServer - httpPlatform.
Attributi di configurazione
| Attributo | Descrizione |
|---|---|
processPath |
Attributo obbligatorio. Percorso dell'eseguibile o dello script che avvierà un processo in ascolto delle richieste HTTP. A partire dalla versione 1.2 sono supportati percorsi relativi, se il percorso inizia con '.' il percorso viene considerato relativo alla radice del sito. Non esiste alcun valore predefinito |
arguments |
Valore stringa facoltativo. Argomenti per l'eseguibile o lo script specificato nell'impostazione processPath. Non esiste alcun valore predefinito. |
startupTimeLimit |
Attributo Integer facoltativo. Durata in secondi per cui HttpPlatformHandler attenderà che il file eseguibile/script avvii un processo in ascolto sulla porta. Se questo limite di tempo viene superato, HttpPlatformHandler terminerà il processo e tenterà di avviarlo nuovamente startupRetryCount volte. Il valore predefinito è 10. |
startupRetryCount |
Attributo Integer facoltativo. Numero di tentativi di avvio del processo specificato in processPath. Per altri dettagli, vedere startupTimeLimit . Il valore predefinito è 10. |
rapidFailsPerMinute |
Attributo Integer facoltativo. Specifica il numero di arresti anomali al minuto per il processo specificato in processPath. Se questo limite viene superato, HttpPlatformHandler interromperà l'avvio del processo per il resto del minuto. L'attributo managedPipelineMode può essere uno dei valori possibili seguenti. Il valore predefinito è 10. |
requestTimeout |
Attributo timespan facoltativo. Specifica la durata per cui HttpPlatformHandler attenderà una risposta dal processo in ascolto su %HTTP_PLATFORM_PORT%. Il valore predefinito è "00:02:00". |
stdoutLogEnabled |
Attributo booleano facoltativo. Se true, stdout e stderr per il processo specificato nell'impostazione processPath verranno reindirizzati al file specificato in stdoutLogFile. Il valore predefinito è false. |
stdoutLogFile |
Attributo di tipo stringa facoltativo. Specifica il percorso di file relativo o assoluto per il quale verranno registrati stdout e stderr dal processo specificato in processPath. I percorsi relativi sono relativi alla radice del sito. A partire dalla versione 1.2 qualsiasi percorso che inizia con '.' sarà relativo alla radice del sito e tutti gli altri percorsi verranno considerati come percorsi assoluti. Il valore predefinito è httpplatform-stdout.. |
processesPerApplication |
Attributo Integer facoltativo. Specifica il numero di istanze del processo specificato nell'impostazione processPath che possono essere attivate per ogni applicazione. Il valore massimo è 100. Il valore predefinito è 1. |
forwardWindowsAuthToken |
Vero o falso. Novità per la versione 1.2. Se questa impostazione è impostata su true, il token verrà inoltrato al processo figlio in ascolto su %HTTP_PLATFORM_PORT% come intestazione "X-IIS-WindowsAuthToken" per ogni richiesta. È responsabilità di tale processo chiamare CloseHandle su questo token per ogni richiesta. Il valore predefinito è false. |
Elementi figli
| elemento | Descrizione |
|---|---|
| environmentVariables | Configura la raccolta environmentVariables per il processo specificato nel parametro processPath. |
| recycleOnFileChange | configura la raccolta di file che ricicla il processo di lavoro quando vengono apportate modifiche al file nell'elenco specificato. Sintassi degli elementi, ad esempio <file path=".\touch.txt"/> o <file path="c:\file.txt"/> |
Esempi di configurazione di HttpPlatformHandler
Di seguito sono riportati esempi di configurazione per l'esecuzione di una serie di applicazioni con processi diversi.
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>
Jetty
<?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="c:\dev\javasites\bin\jetty-distribution-9.2.6.v20141205" -jar "c:\dev\javasites\bin\jetty-distribution-9.2.6.v20141205\start.jar""
startupTimeLimit="20"
startupRetryCount="20"
stdoutLogEnabled="true"></httpPlatform>
</system.webServer>
</configuration>
Codice di esempio
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();
Linea di comando (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'}