Published on Mar 3 2012 in Control Panels Java Tomcat

You can mix Java and non-Java URLs within a single domain with ease thanks to proxy mappings.

We provide our clients with ability to map selected URLs or URL patterns to their application servers so that they could use Java and other language based applications in parallel from 1 account. An example is to have Drupal PHP application and several Java servlets or JSP pages. You might then map everything / (we also call it catch-all mapping) and unmap requests that begin with /drupal from being passed to a Java application server.

Another usage example is when you want some static data like movies, css, images served directly by faster webserver and leave only Java parts to be served by Tomcat. In this case you might unmap /videos, /images and /css or even a single page like /404.html and leave / in Include section. On the other side, when most of your applications are not Java based and you have deployed only single Java application myfirstjavaapp under webapps you may just add /myfirstjavaapp to Include section. Requests that begin with /myfirstjavaapp will be passed to your Tomcat and all other requests will be served by Apache.

Also, thanks to the proxying, clients that use shared IP do not have to specify their application server HTTP port in URLs although they can do so if necessary. JVM Host clients can see ports/protocol assignments on Java Control Panel - Ports page.

In JCP control panel you may choose between 3 mapping methods. We offer mod_jk (AJP), mod_proxy_ajp (AJP) and mod_proxy (HTTP). mod_proxy_ajp is an extension of mod_proxy and inherits most of its properties. If an application server does not support AJP protocol you can only use mod_proxy. mod_jk allows you to use wildcard '*' in path while mod_proxy family does not. So settings from Table 1 are possible with any mapping method but settings from Table 2 are only doable with mod_jk.

On JCP's Mappings page you can see Include and Exclude sections. Rules are applied in Include-first order. Every path that is not in Include or is in Exclude will be served directly by webserver (from ~/public_html in case of cPanel based server).

Common approach in Java hosting is to map everything to an application server and add your non-Java resources to Exclude, for example:

Table 1. Common example
Include Exclude
/ /cpanel
/webmail
/images
/drupal
/downloads
Table 2. mod_jk wildcard example
Include Exclude
/* /cpanel
/cpanel/*
/webmail
/webmail/*
/misc/*.gif
Table 3. mod_jk wildcard example 2
Include Exclude
/pages/*.jsp
/servlets/*
/servlet-examples

The above example setting from Table 1 will activate the following mappings.

In case of mod_jk:

JkMount /* wAJPPORT
JkUnMount /webmail/* wAJPPORT
JkUnMount /webmail wAJPPORT
JkUnMount /cpanel/* wAJPPORT
JkUnMount /cpanel wAJPPORT
JkUnMount /images/* wAJPPORT
JkUnMount /images wAJPPORT
JkUnMount /drupal/* wAJPPORT
JkUnMount /drupal wAJPPORT
JkUnMount /downloads/* wAJPPORT
JkUnMount /downloads wAJPPORT

In case of mod_proxy_ajp:

ProxyPass /webmail !
ProxyPass /cpanel !
ProxyPass /images !
ProxyPass /drupal !
ProxyPass /downloads !
ProxyPass / ajp://localhost:AJPPORT/ retry=5
ProxyPassReverse / ajp://localhost:AJPPORT/

In case of mod_proxy:

ProxyPass /webmail !
ProxyPass /cpanel !
ProxyPass /images !
ProxyPass /drupal !
ProxyPass /downloads !
ProxyPass / http://localhost:HTTPPORT/
ProxyPassReverse / http://localhost:HTTPORT/

Note that when you change mapping method (for example switch from mod_jk to mod_proxy_ajp) any existing non-default mappings will be deleted and you may need to add them again.

Restore Default Mappings button restores / on Include list and /webmail and /cpanel on Exclude list. These are provided to allow cPanel and webmail access on cPanel based servers. Happy mapping :)