We run about 30 webapps on various Tomcat instances behind load balancers and Apache reverse proxies using mod_jk. The public URL of each application is configured into the Apache mod_jk config which proxies to the backend Tomcats. The backend Tomcat runs the application on a context path which matches the public URL.
e.g.
domain.com/foo/bar/webapp -- mod_jk --> tomcat/foo/bar/webapp
This is because the applications build links in the JSPs using ${pageContext.request.contextPath}
, e.g.
<script src="${pageContext.request.contextPath}/resources/js/image-manipulation.js" > </script>
I'd like to make this more loosly coupled, and "containerise" the webapps, so they each run in their own Tomcat container, on the default context, i.e. /
without needing to know what their public URL is. This would simplify managing the Tomcat configuration and mod_jk mappings.
The problem is how can the application build absolute links to within itself, without knowing what it's final public URL is? Is there a way to pass the URL in the mod_jk request, and have Tomcat override calls to ${pageContext.request.contextPath}
with this URL?
Or is it better to use something like mod_substitute
in Apache to replace a fixed string in the page with the URL when it's heading out of Apache? This seems inefficient as Apache has to then scan all the pages doing this find & replace..
Or is it best just to leave it all as it is, and use the context path as currently?