Out of 3, Only one mod_jk worker is not working

apache-2.2mod-jknamevirtualhosttomcat7

I have a server configuration with Apache http Server 2.2 with name based virtual hosts connected to separate Tomcat 7 virtual hosts using mod_jk connector.

Previously 2 Apache Virtual Hosts were successfully serving the separate applications from respective Tomcat Virtual Hosts, but recently when I tried to one more host to the configuration, the new host is not working.

Here is the host declaration in Tomcat's server.xml:

<Host name="localhost"  appBase="webapps/localhost"
      unpackWARs="true" autoDeploy="true">          
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

<Host name="xx1.com"  appBase="webapps/xx1"
      unpackWARs="true" autoDeploy="true">  
    <Alias>www.xx1.com</Alias>        
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="xx1_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

<Host name="xx2.com"  appBase="webapps/xx2"
      unpackWARs="true" autoDeploy="true">
    <Alias>www.xx2.com</Alias>          
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="xx2_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

<Host name="xx3"  appBase="webapps/xx3"
      unpackWARs="true" autoDeploy="true">        
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="xx3_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

Here's the Apache Virtual Hosts config:

<VirtualHost *:80>
ServerName xxx.com
ServerAlias *.xxx.com    
JkMount /* newworker
</VirtualHost>

<VirtualHost *:80>
ServerName xx2.com
ServerAlias *.xx2.com
JkMount /* worker2  
</VirtualHost>

<VirtualHost *:80>
ServerName xx1.com
ServerAlias *.xx1.com    
JkMount /* worker1
</VirtualHost>

The Worker.properties file contents are:

worker.list=worker1, woker2, newworker
worker.worker1.type=ajp13
worker.worker1.host=xx1.com
worker.worker1.port=8009
worker.worker2.type=ajp13
worker.worker2.host=xx2.com
worker.worker2.port=8009
worker.newworker.type=ajp13
worker.newworker.host=xx3
worker.newworker.port=8009

And here is the mod_jk log:

[error] ajp_validate::jk_ajp_common.c (2748): worker newworker can't resolve tomcat address xx3

I think that the issue is with Tomcat, because when to access host xx3 from host-manager app, the application doesn't run. Whereas, xx1.com and xx2.com respond very well.

Note: xx1.com and xx2.com are public domains with their A records pointing to the server where applicatins are running whereas xx3 is a local doamin with no exclusive DNS Record except entry in hosts file.

After putting in a lot of time I have come to notice that worker.host parameter is resolving hostname based on DNS and not just the (virtual) hosts running in Tomcat. Though I find it very strange, it is the root cause of the problem.

Can someone help me configure the server for desired result.

Best Answer

Apache is unable to resolve the hostname xx3 of the worker.

You probably have hard-coded entries in /etc/hosts for xx1.com and xx2.com, but not for xx3.

You can find out by issuing:

$ getent hosts xx2.com

and comparing that to:

$ getent hosts xx3

Also note that:

Clients normally use host names to identify the server they wish to connect to. This host name is also included in the HTTP request headers. Tomcat extracts the host name from the HTTP headers and looks for a Host with a matching name. If no match is found, the request is routed to the default host. The name of the default host does not have to match a DNS name (although it can) since any request where the DNS name does not match the name of a Host element will be routed to the default host.