Use HttpPlatformHandler
適用于:Windows Azure Pack
HttpPlatformHandler 是 Internet Information Services (IIS) 模組,可用於:
管理任何可以在連接埠上接聽 HTTP 要求的處理序 (例如 Tomcat、Jetty、node.exe 及 Ruby)序。
將 Proxy 要求傳送給其所管理的處理序。
HttpPlatformHandler 與 Java Web 應用程式
HttpPlatformHandler 可以搭配 Windows Azure Pack:網站來裝載 JAVA 和其他進程。
您可以使用 FTP、Git、Kudu 和網站的整合式 SCM 功能來部署 JAVA 型網站。
WebDeploy 可用為通訊協定。 由於 Java 並非以 Visual Studio 開發而來,所以 WebDeploy 不適用於 Java Web 應用程式部署使用案例。
設定自訂 Java Web 應用程式的方針
在 Azure 上自訂 Java Web 應用程式需要下列設定:
Java 處理序使用的 HTTP 連接埠會動態指定給環境變數 HTTP_PLATFORM_PORT。 HTTP 接聽程式必須使用此連接埠。
除此 HTTP 接聽程式連接埠之外的所有接聽程式連接埠都必須停用。 在 Tomcat 中,這包括關機、HTTPS 及 AJP 連接埠。
此容器必須設定為僅供 IPv4 流量之用。
應用程式的啟動命令必須在組態中設定。
需要可寫入目錄的應用程式必須位於 Windows Azure Pack: Web Sites 的內容目錄中,也就是 D:\home。 環境變數 HOME 係指 D:\home。
您可以在 Web.config 檔案中設定環境變數。
web.config httpPlatform 組態
HttpPlatformHandler 在您應用程式的 Web.config 檔案中,會使用下列結構描述:
<configSchema>
<sectionSchema name="system.webServer/httpPlatform">
<attribute name="processPath" type="string" expanded="true"/>
<attribute name="arguments" type="string" expanded="true" defaultValue=""/>
<attribute name="startupTimeLimit" type="uint" defaultValue="10" validationType="integerRange" validationParameter="0,3600"/> <!-- in seconds -->
<attribute name="startupRetryCount" type="uint" defaultValue="10" validationType="integerRange" validationParameter="0,100"/>
<attribute name="rapidFailsPerMinute" type="uint" defaultValue="10" validationType="integerRange" validationParameter="0,100"/>
<attribute name="requestTimeout" type="timeSpan" defaultValue="00:02:00" validationType="timeSpanRange" validationParameter="0,2592000,60"/>
<attribute name="stdoutLogEnabled" type="bool" defaultValue="false" />
<attribute name="stdoutLogFile" type="string" defaultValue="httpplatform-stdout" expanded="true"/>
<attribute name="processesPerApplication" type="uint" defaultValue="1" validationType="integerRange" validationParameter="1,100"/>
<element name="environmentVariables">
<collection addElement="environmentVariable" clearElement="clear">
<attribute name="name" type="string" required="true" validationType="nonEmptyString"/>
<attribute name="value" type="string" required="true"/>
</collection>
</element>
</sectionSchema>
</configSchema>
arguments (default = 「」) :傳送至 processPath 屬性所識別之 HTTP 接聽程式的引數。
範例 (含 processPath):
processPath="%HOME%\site\wwwroot\bin\tomcat\bin\catalina.bat"
arguments="start"
processPath="%JAVA_HOME\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Djetty.port=%HTTP\_PLATFORM\_PORT% -Djetty.base="%HOME%\site\wwwroot\bin\jetty-distribution-9.1.0.v20131115" -jar "%HOME%\site\wwwroot\bin\jetty-distribution-9.1.0.v20131115\start.jar""
processPath:HTTP 接聽程式可執行檔的路徑或指令碼。
範例:
processPath="%JAVA_HOME%\bin\java.exe"
processPath="%HOME%\site\wwwroot\bin\tomcat\bin\startup.bat"
processPath="%HOME%\site\wwwroot\bin\tomcat\bin\catalina.bat"
rapidFailsPerMinute (default = 10):每分鐘允許 HTTP 接聽程式處理序損毀的次數。 若超出此限制,HttpPlatformHandler 在該分鐘的剩餘時間內,會停止啟動該處理序。
requestTimeout (default = "00:02:00"):HttpPlatformHandler 等候來自接聽 %http_platform_port% 之處理序的回應的時間量。
startupRetryCount (default = 10):HttpPlatformHandler 嘗試啟動 HTTP 接聽程式處理序的次數。
startupTimeLimit (default = 10 seconds):HttpPlatformHandler 等候 HTTP 接聽程式開始接聽通訊埠之處理序的時間量。 若超出此時間限制,HttpPlatformHandler 會停止 HTTP 接聽程式,然後依據 startupRetryCount 的設定值嘗試重新啟動該接聽程式。
stdoutLogEnabled (default = "true"):若為 True,stdout 及 stderr HTTP 接聽程式會被重新導向至 stdoutLogFile 所指定的檔案。
stdoutLogFile (default="d:\home\LogFiles\httpPlatformStdout.log"):HTTP 接聽程式到 stdout 及 stderr 記錄的絕對檔案路徑。
注意
%HTTP_PLATFORM_PORT% 是必須指定為引數 屬性或 HTTPPlatformEnvironmentVariables 清單一部分 的特殊預留位置。 HttpPlatformHandler 會以連接埠動態取代此變數,以便於 HTTP 接聽程式可以接聽此連接埠。
應用程式組態範例
針對下列 Tomcat 和 Jetty 範例,範例Web.config檔案和應用程式組態示範如何在 Windows Azure Pack:Web Sites 上啟用 JAVA 應用程式。
Tomcat
下列範例示範在 JAVA 虛擬機器上安裝 Tomcat:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%HOME%\site\wwwroot\bin\tomcat\bin\startup.bat"
arguments="">
<environmentVariables>
<environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT%" />
<environmentVariable name="CATALINA_HOME" value="%HOME%\site\wwwroot\bin\tomcat" />
<environmentVariable name="JRE_HOME" value="%HOME%\site\wwwroot\bin\java" /> <!-- optional, if not specified, this will default to %programfiles%\Java -->
<environmentVariable name="JAVA_OPTS" value="-Djava.net.preferIPv4Stack=true" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
Tomcat 組態也必須隨之變更。 伺服器 XML 的設定需必須編輯如下:
關機連接埠 = -1
HTTP 連接器連接埠 = ${port.http}
HTTP 連接器位址 = "127.0.0.1"
註解化 HTTPS 和 AJP 連接器
您也可以在 catalina.properties 檔案中設定 IPv4 設定,您可以在其中新增 java.net.preferIPv4Stack=true。
Windows Azure Pack:Web Sites 不支援 Direct3D 呼叫。 如果您的應用程式進行這類呼叫,請新增下列 JAVA 選項加以停用:-Dsun.java2d.d3d=false。
Jetty
以下是執行 Jetty 完整安裝的範例組態:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httppPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Djetty.port=%HTTP_PLATFORM_PORT% -Djetty.base="%HOME%\site\wwwroot\bin\jetty-distribution-9.1.0.v20131115" -jar "%HOME%\site\wwwroot\bin\jetty-distribution-9.1.0.v20131115\start.jar""
startupTimeLimit="20"
startupRetryCount="10"
stdoutLogEnabled="true">
</httpPlatform>
</system.webServer>
</configuration>
Jetty 組態必須在起始 INI 檔案中變更,如下所示:java.net.preferIPv4Stack=true。
使用 HttpPlatformHandler 裝載 Java 應用程式
若要使用 HttpPlaftormHandler 裝載 Java 應用程式,請遵循下列步驟:
使用租用戶的管理入口網站建立空白網站。
例如,從 http://tomcat.apache.org/) 下載 Tomcat (複本,並將 zip 檔案解壓縮到開發電腦上的資料夾 (,例如:c:\dev\javasites\bin\apache-tomcat-8.0.15) 。
將 Java Development Kit 加入 Tomcat 所在的資料夾 (例如 c:\dev\javasites\bin\jdk1.7.0_79)。
依照前文 Tomcat 範例所述,變更 Tomcat 組態。
將您要使用的 Java 應用程式 (例如 Pebble 部落格工具) 下載到 webapps 資料夾。
使用文字編輯器建立新的 Web.config 檔案,並將其加入您的網站資料夾中 (例如 c:\dev\javasites\web.config)。
編輯 Web.config 檔案,以加入 HttpPlatformHandler 組態,如下所示。 此組態會指定 Tomcat 伺服器及 JDK 目錄的位置、設定 Catalina,以及定義 Pebble 所需的 ${user.home} 變數:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" /> </handlers> <httpPlatform processPath="%HOME%\site\wwwroot\bin\apache-tomcat-8.0.15\bin\startup.bat" arguments=""> <environmentVariables> <environmentVariable name="JRE_HOME" value="%HOME%\site\wwwroot\bin\jdk1.7.0_79" /> <environmentVariable name="CATALINA_OPTS" value="-Dport.http=%HTTP_PLATFORM_PORT% -Dsomeotherconfig=value" /> <environmentVariable name="CATALINA_HOME" value="%HOME%\site\wwwroot\bin\apache-tomcat-8.0.15" /> <environmentVariable name="JAVA_OPTS" value="-Duser.home=%HOME%/site/wwwroot/user_home"/> </environmentVariables> </httpPlatform> </system.webServer> </configuration>
將 c:\dev\javasites 的內容上傳到您在步驟 1 中建立之網站的 wwwroot 資料夾。
若要流覽至 Pebble JAVA 應用程式,請將 /pebble 附加至根 URL (例如) http://javawebsite.awbl-s.redant.selfhost.corp.microsoft.com/pebble/ 。