Question

I am connecting to two tomcat application via the ajp protocol. both of which are running in separate tomcat virtual host as ROOT.war. On the server, I have configured the /etc/hosts file

127.0.0.1       localhost  tcvh1 tcvh2

apache httpd.conf:

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
        #ProxyPreserveHost On
        ServerName app1.example.com
        ProxyPass / ajp://tcvh1:8082/
        ProxyPassReverse / ajp://tcvh1:8082/

</VirtualHost>

<VirtualHost *:80>
        #ProxyPreserveHost On
        ServerName app2.example.com
        ProxyPass / ajp://tcvh2:8082/
        ProxyPassReverse / ajp://tcvh2:8082/
</VirtualHost>

Tomcat :

I have the applications deployed as: app1 -- $CATALINA_HOME/tcvh1/ROOT.war app2 -- $CATALINA_HOME/tcvh2/ROOT.war

Now, If I changed the tomcat to run on port 8080, and changed the proxy pass to connect to http://tcvh1:8080, then it works. but if I used the configuration with AJP, it does NOT work.

Why does my host alias not work with AJP? is there a way to make it work?

Was it helpful?

Solution

It doesn't work because the mod_proxy_ajp always passes the host header received by httpd to Tomcat whereas the mod_proxy_http will use the host defined in the ProxyPass unless ProxyPreserveHost is set to On.

Since - as far as httpd is concerned - your virual hosts are app1.example.com and app2.example.com, these are what get passed to your Tomcat instance. Tomcat has no record of these virtual hosts. It has tcvh1 and tcvh2. Therefore all the requests will get routed to the default virtual host (which ever one is defined on your Engine element in server.xml).

There are several ways to fix this:

  1. Rename you Tomcat virtual hosts to match your httpd virtual hosts
  2. Add aliases ( see http://tomcat.apache.org/tomcat-7.0-doc/config/host.html#Host_Name_Aliases) to your Tomcat virtual hosts.

Personally, I'd go with option 2. Quicker and simpler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top