Staffan Runnsjö
Staffan Runnsjö

Reputation: 86

"ajp_ilink_receive failed" when trying to connect a non-Docker Apache to a Docker Tomcat through AJP

I have problems routing Apache (not run in a docker container) through AJP to a Tomcat running in a Docker container. The configuration of Apache and Tomcat works when run without Docker, but as soon as I run Tomcat in docker it stops working: there is something I am missing in the port configuration is my guess.

Apart from below configurations I have tried network_mode: host in the docker-compose. That allows my requests through but I can't use it since this must run on non-linux hosts too.

Please help me find what needs to be done differently when connecting a non-Docker Apache to a Docker-Tomcat.

This is my error.log from Apache

[Mon Mar 01 14:03:42.650251 2021] [proxy_ajp:error] [pid 4603:tid 140128592954944] [client 127.0.0.1:52788] AH00992: ajp_read_header: ajp_ilink_receive failed
[Mon Mar 01 14:03:42.650278 2021] [proxy_ajp:error] [pid 4603:tid 140128592954944] (120006)APR does not understand this error code: [client 127.0.0.1:52788] AH00878: read response failed from 127.0.0.1:8009 (staffan)

This is the proxypass part of my apache configuration

ProxyPass / ajp://staffan:8009/ timeout=600 secret=mySecret
ProxyPassReverse / ajp://staffan:8009/ secret=mySecret

And this is the corresponding part of server.xml in tomcat

<Connector port="8009"
  protocol="AJP/1.3"
  redirectPort="8443"
  asyncTimeout="60000"
  maxPostSize="52428800"
  allowedRequestAttributesPattern=".*"
  secret="mySecret"/>

Docker file (built with #docker build -t my-docker .)

FROM tomcat:9
ENV JPDA_ADDRESS=*:5005
ENV JPDA_TRANSPORT=dt_socket
WORKDIR /
COPY ./deploy/server.xml /usr/local/tomcat/conf/
COPY ./deploy/context.xml /usr/local/tomcat/conf/
COPY ./deploy/web.xml /usr/local/tomcat/conf/
COPY ./build/libs/localhost.war /usr/local/tomcat/webapps/.
CMD ["catalina.sh", "jpda", "run"]

And docker compose

version: "3.8"

services:
  my-development:
    image: my-docker
    restart: unless-stopped
    mem_limit: 16gb
    ports:
      - 8009:8009
      - 9080:9080
      - 5005:5005
    volumes:
      - my-io:/io
      - logs:/logs

volumes:
  my-io:
    external: true
    name: my-io
  logs:
    name: logs

Upvotes: 0

Views: 1604

Answers (1)

Staffan Runnsj&#246;
Staffan Runnsj&#246;

Reputation: 86

The problem was in the networking; you must tell Tomcat to listen to all addresses (as Apache is outside the container) using the address attribute

 <Connector port="8009"
               protocol="AJP/1.3"
               asyncTimeout="60000"
               maxPostSize="52428800"
               allowedRequestAttributesPattern=".*"
               packetSize="32768"
               secret="mySecret"
               address="0.0.0.0"/>

Upvotes: 1

Related Questions