14

I'm trying to resolve an issue about connecting Apache and Tomcat with mod_proxy_ajp. In my case, the Tomcat stops to response the Apache, and the apache log prints logs error message like this:

[Mon May 06 15:22:47 2013] [error] ajp_read_header: ajp_ilink_receive failed
[Mon May 06 15:22:47 2013] [error] (120006)APR does not understand this error code: proxy: read response failed from [::1]:18009 (localhost)

I have no idea. Anyone can help me?

0

5 Answers 5

15

Add connectionTimeout and keepAliveTimeout to your AJP connector found in /etc/tomcat7/server.xml.

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" 
           connectionTimeout="10000" keepAliveTimeout="10000" />

Info about the AJP connector at https://tomcat.apache.org/tomcat-7.0-doc/config/ajp.html

  • connectionTimeout = The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. The default value for AJP protocol connectors is -1 (i.e. infinite).

  • keepAliveTimeout = The number of milliseconds this Connector will wait for another AJP request before closing the connection. The default value is to use the value that has been set for the connectionTimeout attribute.

If connectionTimeout and keepAliveTimeout values is not defined, then AJP connections will be kept alive for infinite. Causing to many threads, default max threads is 200.

I recommend installing psi-probe - an advanced manager and monitor for Apache Tomcat, forked from Lambda Probe. https://code.google.com/p/psi-probe/

1
  • 1
    "If connectionTimeout and keepAliveTimeout values is not defined, then AJP connections will be kept alive for infinite." Actually if connectionTimeout is set, tomcat will use that value for keepAliveTimeout. So you only need to set connectionTimeout. tomcat.apache.org/tomcat-7.0-doc/config/ajp.html
    – Alkanshel
    Jan 22, 2020 at 22:14
6

a very good explanation of the problem and how to solve it can be found at http://javaworkbench.blogspot.co.at/2013/09/apache-web-server-tomcat-ajp.html.

in short: - Configure Apache 'MaxClients' to be equal to the Tomcat AJP 'maxConnections' configuration. - Configure Tomcat AJP 'keepAliveTimeout' to close connections after a period of inactivity.

5

I am using tomcat 8 with apache 2.2 and Centos, found the issue saying:

[error] ajp_read_header: ajp_ilink_receive failed
[error] (70007)The timeout specified has expired: proxy: read response failed

The solution I applied and it worked perfect:

1. Configure Apache 'MaxClients' to be equal to the Tomcat AJP 'maxConnections' configuration.
2. Configure Tomcat AJP 'keepAliveTimeout' to close connections after a period of inactivity.

Here is an example from tomcat server.xml:

<Connector port="8009" protocol="AJP/1.3" maxConnections="256" keepAliveTimeout="30000" redirectPort="8443" />

vote for answer if you liked this solution. cheers

4

Try this :

  1. try with increase the number of thread count. (It will postpone the errors)
  2. In tomcat configuration try "org.apache.coyote.ajp.AjpProtocol" instead the APR.
4
  • Do you mean replace <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> with <Listener className="org.apache.coyote.ajp.AjpProtocol" SSLEngine="on" /> in server.xml?
    – sezina
    May 6, 2013 at 9:35
  • yes. I'm not sure but may be it will work for you. so try it once. May 6, 2013 at 9:36
  • I have tried it. But I got other errors [Mon May 06 17:21:26 2013] [error] proxy: AJP: disabled connection for (localhost) [Mon May 06 17:24:55 2013] [error] (111)Connection refused: proxy: AJP: attempt to connect to 127.0.0.1:18019 (localhost) failed [Mon May 06 17:24:55 2013] [error] ap_proxy_connect_backend disabling worker for (localhost) [Mon May 06 17:24:55 2013] [error] proxy: AJP: failed to make connection to backend: localhost.
    – sezina
    May 6, 2013 at 10:06
  • can you go through this link. It contains the solution of almost all the errors of this kind. serverfault.com/questions/19947/… May 6, 2013 at 10:15
0

I had the same problem and I wonder why I couldn't find anything about my solution: I simply had to set secretRequired to false in the Connector config:

<Connector protocol="AJP/1.3"
           address="127.0.0.1"
           port="8009"
           redirectPort="8443"
           secretRequired="false"
/>

My Apache HTTPD config:

ProxyPass        /tomcat10 ajp://localhost:8009/

Be aware that this could be insecure. Maybe it's better to keep secretRequired="true" and fix it on the Apache HTTPD side. I just wanted to give at least a hint on what could be wrong for others having the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.