When using Apache HTTP Server (2.2.3+) with Tomcat 6+ through mod_proxy_ajp, you might encounter timeout issues with requests that take unusually long to process (2-6 minutes in this case). The default timeout settings can prematurely terminate these long-running connections.
By default, mod_proxy_ajp has several timeout-related parameters that might affect your connection:
- Connection timeout (default: varies by Apache version)
- Keepalive timeout
- Worker timeout
Here's how to modify your configuration to handle long-running requests:
# In your Apache configuration (httpd.conf or included file)
<Location /blah>
ProxyPass ajp://localhost:8010/blah timeout=600
ProxyPassReverse ajp://localhost:8010/blah
ProxyTimeout 600
</Location>
For a more robust setup, consider these additional parameters:
<IfModule mod_proxy_ajp.c>
ProxyRequests Off
ProxyPreserveHost On
ProxyTimeout 600
<Proxy ajp://localhost:8010/blah>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Timeout 600
ProxySet connectiontimeout=600 timeout=600
</Proxy>
<Location /blah>
ProxyPass ajp://localhost:8010/blah timeout=600 ping=60
ProxyPassReverse ajp://localhost:8010/blah
</Location>
</IfModule>
When dealing with long-running requests:
- Consider implementing asynchronous processing if possible
- Monitor your AJP worker threads in Tomcat
- Adjust Tomcat's connectionTimeout if needed
- Test with various timeout values to find the optimal setting
If you're still experiencing issues:
# Check Apache error logs
tail -f /var/log/httpd/error_log
# Enable debug logging for mod_proxy
LogLevel debug proxy:trace5
When dealing with Apache-to-Tomcat AJP proxying, the default timeout settings often prove insufficient for processing long-running operations. The typical symptoms include:
- Requests failing after exactly 2 minutes
- 503 Service Unavailable errors
- Connection reset exceptions in Tomcat logs
For Apache 2.2 with mod_proxy_ajp, these directives control timeout behavior:
ProxyPass /blah ajp://localhost:8010/blah timeout=600
ProxyPassReverse /blah ajp://localhost:8010/blah
The critical parameter here is timeout=600
(10 minutes). Without this, Apache uses its default 2-minute timeout.
Your Tomcat AJP connector must also be configured for long-running requests:
<Connector port="8010" protocol="AJP/1.3"
connectionTimeout="600000"
keepAliveTimeout="300000"
maxThreads="200"
redirectPort="8443" />
For very complex setups, consider these additional parameters:
# Apache global settings (httpd.conf)
Timeout 600
ProxyTimeout 600
# Per-location configuration
<Location /long-process>
ProxyPass ajp://backend:8009/long-process timeout=600 retry=10
ProxyPassReverse ajp://backend:8009/long-process
ProxyPassReverseCookieDomain backend yourdomain.com
</Location>
Verify your configuration with these commands:
apachectl -M | grep proxy # Verify mod_proxy modules
tail -f /var/log/httpd/error_log # Monitor timeout events
curl -v http://localhost/blah/long-process # Test connectivity
Remember that increasing timeouts affects resource utilization. Monitor your system's memory and thread usage after implementing these changes.