- Published on
Configuring Tomcat in Azure App Service: Increase maxParameterCount
- Authors
- Name
- Jeevan Wijerathna
- @iamjeevanvj
When hosting Java web applications on Azure App Service using Tomcat, you might encounter issues with legacy Java applications due to the default
maxParameterCount
In this guide, I'll walk you through a quick and effective way to increase the
maxParameterCount
Understanding the Problem
By default, Tomcat sets a limit of 1000 parameters that can be processed in a single HTTP request. This includes:
- Form fields in POST requests
- URL parameters in query strings
- Multiple values for the same parameter name
When your application exceeds this limit, Tomcat will ignore additional parameters, potentially breaking your application's functionality without clear error messages.
Solution: Custom Startup Script
We'll create a startup script that:
- Modifies the configuration file
server.xml
- Updates the value
maxParameterCount
- Starts Tomcat with the new configuration
Step 1: Create a Startup Script
There are several ways to create and upload the startup script to your Azure App Service:
Option 1: Using the Kudu Console (Azure App Service Advanced Tools)
- Navigate to your Azure App Service in the Azure Portal
- Go to Development Tools > Advanced Tools > Go
- In the Kudu console, click on Debug console > SSH
- Navigate to the directory
/home
- Click on the + button > New File and name it
startup.sh
- Copy and paste the following script:
#!/bin/bash # Update maxParameterCount from 1000 to 10000 in server.xml set -e SERVER_XML="/usr/local/tomcat/conf/server.xml" NEW_VALUE="10000" echo "[$(date)] Starting Tomcat configuration update..." # Backup original file cp "$SERVER_XML" "${SERVER_XML}.backup" echo "[$(date)] Backup created." # Update value sed -i 's/maxParameterCount="1000"/maxParameterCount="'"$NEW_VALUE"'"/g' "$SERVER_XML" echo "[$(date)] Updated maxParameterCount to $NEW_VALUE" # Verify update if grep -q "maxParameterCount=\"$NEW_VALUE\"" "$SERVER_XML"; then echo "[$(date)] Configuration update successful" else echo "[$(date)] ERROR: Update failed, restoring backup" cp "${SERVER_XML}.backup" "$SERVER_XML" exit 1 fi # Start Tomcat echo "[$(date)] Starting Tomcat..." exec catalina.sh run
- Save the file
- In the SSH console, run:
chmod +x /home/startup.sh
Option 2: Using FTP/FTPS
- Set up FTP/FTPS credentials in your App Service (under Deployment Center > FTPS credentials)
- Create the script locally on your computer
- Upload the file to the directory using your preferred FTP client (like FileZilla)
/home
- Connect to the Kudu SSH console as described above and run:
chmod +x /home/startup.sh
Option 3: Using Azure CLI
- Create the script locally on your computer (e.g., )
startup.sh
- Use Azure CLI to upload it:
# Login to Azure az login # Set your subscription (if you have multiple) az account set --subscription <your-subscription-id> # Upload the file to the App Service az webapp deploy --resource-group <your-resource-group> --name <your-app-name> --src-path startup.sh --target-path /home/startup.sh # Connect to the App Service using SSH az webapp ssh --resource-group <your-resource-group> --name <your-app-name> # Inside the SSH session, make the script executable chmod +x /home/startup.sh
This script performs the following operations:
- Creates a backup of the original configuration file
- Uses to replace the default value with our new value
sed
- Verifies the change was successful
- Starts Tomcat with the updated configuration
Step 2: Configure App Service to Use the Script
- Navigate to your Azure App Service in the Azure Portal
- Go to Configuration > General settings
- In the Startup Command field, enter:
/home/startup.sh
- Click Save
Verification and Testing
After deploying your changes:
- Check the application logs in Log stream to verify the script executed successfully
- Look for messages like: and
[date] Updated maxParameterCount to 10000
[date] Configuration update successful
- Test your application with a request that contains more than 1000 parameters
Important Considerations
- Always test configuration changes in a staging slot before deploying to production
- This approach assumes you're using Tomcat on Linux in Azure App Service
- The exact path to may vary depending on your Tomcat version and configuration
server.xml
- Consider security implications of increasing this limit, as very large requests could potentially be used in DoS attacks
Conclusion
By implementing this custom startup script, you can easily increase Tomcat's
maxParameterCount
For more complex scenarios or additional Tomcat configuration needs, you might consider creating a custom Docker image with your preferred settings pre-configured.