Tomcat – AJP Connector not working? (404 error)

ajpapache-2.4connectormod-jktomcat

I'm trying to connect the Apache WebServer (2.4.10) to Tomcat 7, both located in two different VMs. It's my first time using those tools. From what I understood a method to check if the connection is working is to try to access to Tomcat using the URL IP/instance instead of, if I have Tomcat on the 8080 port, IP:8080/instance. However, everytime I try to do that, a 404 error is returned by Apache. Here's my configuration:

On the Tomcat's VM, server.xml has the line:

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

On the Apache's VM, I have set those files:

apache2.conf (in the Apache main folder)

Servername apache
Include httpd.conf
ServerRoot "/etc/apache2"

Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

httpd.conf (in the Apache main folder, symbolic link in conf-available and conf-enabled)

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

workers.properties (in /etc/libapache2-mod-jk)

workers.tomcat_home=/usr/share/tomcat7

workers.java_home=/usr/lib/jvm/java-7-openjdk-amd64

ps=/

worker.list=agent1
worker.maintain=3600

worker.agent1.port=8009
worker.agent1.host=192.168.2.97
worker.agent1.type=ajp13

worker.agent1.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=agent1

jk.conf (in mods-available folder, link in mods-enabled)

JkWorkersFile /etc/libapache2-mod-jk/workers.properties

JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel debug
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

JkShmFile /var/log/apache2/jk-runtime-status

JkWatchdogInterval 60

JkMount     /gameoflife/*   agent1 
JkMount     /gameoflife     agent1
JkMount     /gameoflife*    agent1

<Location /jk-status>
    JkMount jk-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>
<Location /jk-manager>
    JkMount jk-manager
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>

I know it can be a mess because I tried following different guides and doing everything to have it working but I still get 404 errors. How can I have it working?

Best Answer

For some reasons, it started working once I tried (in the desperation) to implement a load balancer even without the AJP connector working on the single server, given that this was from the beginning my final goal. Ultra happy.

At the end I also wrote the JkMount instructions in the 000-default.conf file in sites-enabled, precisely in the VirtualHost< *:80> istruction. Maybe this was needed in order to work properly.