aspose file tools*
The moose likes Tomcat and the fly likes Struggling with configuration of Tomcat through Apache mod_proxy_ajp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Struggling with configuration of Tomcat through Apache mod_proxy_ajp" Watch "Struggling with configuration of Tomcat through Apache mod_proxy_ajp" New topic
Author

Struggling with configuration of Tomcat through Apache mod_proxy_ajp

Dave Genarro
Greenhorn

Joined: Oct 25, 2010
Posts: 2
Hi folks,

I'm a newbie to Tomcat and I can't help but think I'm missing something obvious, but maybe you can help.

I have Apache2.2 and Tomcat6 running on the same server. I want to run Tomcat through Apache so that everything is accessible through the same hostname/port and protected by SSL (intranet portal). There is a lot of other stuff on the apache installation, so I would like Tomcat to have its own namespace under https://my.host/tomcat/ . So far I have established that there are several ways to do this, but mod_proxy_ajp seems to be the latest and greatest. (is that correct?)

I have added the following lines to /etc/apache2/mods-enabled/proxy.conf:


ProxyPass /tomcat/ ajp://localhost:8009/
ProxyPassReverse /tomcat/ ajp://localhost:8009/


And the following to my Tomcat installation's server.xml:


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


Success! on https://my.host/tomcat/ I can access the tomcat default page, however the urls of all the links have a path to my host's root. Eg the link to the manager application points to https://my.host/manager/html, when it should be https://my.host/tomcat/manager/html . The manager application is sitting where I want it, the link leads to a 404 until I manually correct in my address bar, adding the /tomcat/ in.

I've been struggling with this as every search I can think of seems to come up with answers about changing the filesystem path where applications are located on the server, rather than the url paths to access them. Do I need to use urlrewrite filter? It seems like an over-complicated solution for something that should have a simple Tomcat configuration option that I am missing.

Thanks for any input.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Actually, the ajp proxy is used more commonly to hide Tomcat, rather than to make it visible. For example, I might set up a URL to http://www.myserver.com/webapp1 which is proxied via ajp to www.myserver.com:8009/webapp1, where "webapp1" is the WAR deployed under the Tomcat responding via ajp at port 8009.

This permits me to structure all webapps as first-class URLs, whether they're Tomcat apps or apache apps, with no difference visible to the end user. In fact, sometimes I'll even do virtual hosting so that http://myapp.myserver.com is proxied to localhost:8009/webapp1. You could do something similar, using a proxy from https://www.myserver.com/tomcat-manager to ajp://localhost:8009/manager.


Customer surveys are for companies who didn't pay proper attention to begin with.
Dave Genarro
Greenhorn

Joined: Oct 25, 2010
Posts: 2
I'm not particularly bothered about the cosmetic aspects of having first-level URLs, the only restriction on that is that everything must be under the same hostname so our single-domain SSL certificate remains valid. My thinking was that I could create a namespace for Tomcat and then manage my application deployments through Tomcat without having to modify my Apache configuration all the time. From looking around it seems that this is not possible (or at least, not straightforward enough to be worthwhile). I have things working with first-level URLs as you describe, so I guess that's the way forward.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

You could probably cobble up some sort of mechanism to do what you want, but it's probably not worth the effort.

Most installations keep a fairly static list of webapps, so maintaining them manually isn't considered a big deal.

In my case, I build deployables as OS install packages (usually for Red Hat Linux), and that means that when I deploy, the package manager adds a config file with the ajp proxy info and other apache-specific stuff to /etc/httpd/conf.d, copies the WAR to the /opt (installed 3d-party applications) directory tree, and sets up a context xml file in the TOMCAT_HOME/conf/Catalina/localhost directory.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struggling with configuration of Tomcat through Apache mod_proxy_ajp