Proxying one context from the front end to another on the backend through mod_jk

Solution Verified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP)
  • JBoss Enterprise Web Server (EWS)
  • Apache httpd
  • mod_jk

Issue

  • How can we proxy one context on our httpd front end to another on our JBoss backend through mod_jk? For example, we want localhost/context1 to proxy to localhost:8009/context2.

Resolution

  • The only way to potentially do this is to use a passthrough rewrite in combination with mod_jk, for example:
RewriteEngine On
RewriteRule ^/context1(.*)$ /context2$1 [PT]
Header edit Location ^([^/]*//[^/]*)?/context2(.*)$ $1/context1$2 
Header edit Set-Cookie "^(.*; Path=)/context2(.*)" $1/context1$2
JkMount /context2* loadbalancer
  • This isn't a use case mod_jk handles very cleanly config wise. It could potentially introduce issues with broken redirects and cookies as mod_jk provides no way to reverse cookie paths or redirect locations.
  • Note the backend in the scenario above would by default provide /context2 path cookies, which would not apply when the client requests /context1. Redirects would also be to /context2. The header edits included above should correct outgoing redirect Location and Set-Cookie headers to match the needed frontend /context1.
  • As alternatives, instead consider:
    • Using mod_proxy, which handles this more easily and more capably with redirect/cookie pass reverses
    • Updating the backend configuration to serve the same context as the front end if using mod_jk

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments