【App Service for Windows】为 App Service 配置自定义 Tomcat 环境

发布时间 2023-12-25 21:53:36作者: 路边两盏灯

问题描述

当在App Service for Windows环境中所列出的Tomcat Version 没有所需要的情况下,如何实现自定义Tomcat 环境呢?

 

问题解答

第一步: 从官网下载要使用的 tomcat 版本,解压到本地目录

 

第二步:修改 conf/server.xml 配置文件

    • 将 port 改成 -1

      02

    • 将 Http-connect port 改成 ${port.http}

      03

    • 注释 AJP 和 HTTPS 连接

      04

    • 将 host 改变为 127.0.0.1,并将 appBase 定位到 wwwroot 下的 webapps 目录:

      若 appbase 定位的是 ../../webapps,那项目文件应该放在 site-->wwwroot-->webapps-->ROOT 目录下。
      若 appbase 定位的是 webapps,那项目文件应该放在 /site/wwwroot/bin/apache-tomcat-<version>/webapps/ROOT

      05

 

第三步:修改 conf/catalina.properties 文件,末尾加入 java.net.preferIPv4Stack=true

 

 

第四步:上传 Tomcat/java 目录到 site/wwwroot/bin

 

第五步:在 site/wwwroot 目录下上传 web.config 内容如下:

<?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="C:\home\site\wwwroot\bin\java\jdkx.x.x_xx\jrex" /> 
        <environmentVariable name="JAVA_OPTS" value="-Djava.net.preferIPv4Stack=true" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

 

重启网站。以检查配置是否生效。