When running Tomcat applications in Linux App Service using built-in Java Tomcat docker image, sometime you may need to customize your Tomcat configuration.
In this blog, we will provide detailed steps of how to modify the default server.xml file in the built-in docker container.
Before trying to overwrite the existing server.xml, please make sure whether it's possible to make your configuration changes in context.xml or web.xml.
Reference doc:
https://tomcat.apache.org/tomcat-9.0-doc/config/server.html
https://tomcat.apache.org/tomcat-9.0-doc/config/context.html
https://tomcat.apache.org/tomcat-9.0-doc/config/filter.html
There are two options that you can use to modify the built-in server.xml file in App Service built-in Java Tomcat docker image.
1. Go to WEBSSH, https://<webapp-name>.scm.azurewebsites.net/webssh/host
2. Copy the built-in server.xml file to any place under /home
cp /usr/local/tomcat/conf/server.xml /home/server.xml
3. Directly make change to /home/server.xml file
vi /home/server.xml
4. Create your customer startup script in any place under /home
vi /home/startup.sh
The contents of the startup.sh file should include the followings:
#!/bin/bash
echo "Using customer server.xml to overwrite /usr/local/tomcat/conf/server.xml"
cp /home/server.xml /usr/local/tomcat/conf/server.xml
echo "server.xml modified"
5. Go to Configuration portal to set "Startup Command", point it to your /home/startup.sh
1. Go to WEBSSH, https://<webapp-name>.scm.azurewebsites.net/webssh/host
2. Use cat command to get the contents of the built-in server.xml file
cat /usr/local/tomcat/conf/server.xml
Copy the file contents into your Notepad on your local machine. Later you can put the server.xml content into online XSL test tool (e.g. https://www.freeformatter.com/xsl-transformer.html) to test your XSL transform file.
3. Write xsl transform file, which can be used to transfer the server.xml contents
For example: I can use the following xsl file to modify my Tomcat access log format (add original client IP address in the log file).
Original XML contents:
Sample transform.xsl file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/Server/Service/Engine/Host/Valve/@pattern">
<xsl:attribute name="pattern">
<xsl:value-of select="'%h %l %u %t "%r" %s %b %D %{x-forwarded-for}i %{x-arr-log-id}i'"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Modified XML contents:
Note:
4. Upload your transform.xsl file to anywhere under /home folder.
Go to https://<webapp-name>.scm.azurewebsites.net/newui/fileManager
5. Create your customer startup script anywhere under /home (e.g. /home/startup.sh)
vi /home/startup.sh
The contents of the startup.sh file should include the followings:
#!/bin/bash
echo "Install libxslt";
apk add --update libxslt;
echo "Using /home/transform.xsl to modify /usr/local/tomcat/conf/server.xml"
xsltproc --output /usr/local/tomcat/conf/server.xml /home/transform.xsl /usr/local/tomcat/conf/server.xml;
echo "server.xml modified"
6. Go to Configuration portal to set "Startup Command", point it to your /home/startup.sh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.