glockman glockman - 2 months ago 29
Apache Configuration Question

How to Use Apache to Proxy to Single Page Application on Weblogic Cluster

As part of upgrading a legacy Java application (hosted on Weblogic cluster), one section of this application will be replaced by a single page application (REACT), calling out over an API to various services that contain migrated backend functionality. For now until all UI dependencies are ported off the legacy application, the REACT SPA will still be hosted inside a JSP page (some common JSP code has not been ported, and so will be present on the JSP page hosting the react app).

The infrastructure hosting this setup is currently an Apache server, routing to the Weblogic cluster or newer services as needed. Proxying to the weblogic cluster was simple before, as all *.jsp pages were routed to the cluster with a simple weblogic plugin block:

<IfModule mod_weblogic.c>
WebLogicCluster server1:port,server2:port
MatchExpression *.jsp
</IfModule>


However with the new SPA, I also need a whole set of routes to proxy to a single .jsp page containing my SPA. If my goal was only to proxy by path, I could solve that easily with apache weblogic plugin:

<Location /newSection/>
WLSRequest On
WebLogicCluster server1:port,server2:port
PathTrim /newSection/
PathPrepend SPA.jsp
DefaultFileName SPA.jsp
</Location>


However this only works for the base /newSection/ url, as a url like

http://host/newSection/spa-route


gets proxied to

http://host/SPA.jsp/spa-route


which is obviously not valid.

No amount of PathTrim, PathPrepend, or anything else I try for the weblogic plugin solves the problem that I am trying to proxy by path to a single URI (everything needs to proxy to http://host/SPA.jsp, SPA router handles the rest)

I am currently experimenting with just using mod_rewrite and mod_proxy instead, as RewriteRule [P] allows me to proxy to a single URI on the cluster (cluster IP coming from Proxy balancer). However this is much more complicated to set up (still trying), and I have to implement things like session stickiness myself.

A solution for how to use the mod_weblogic plugin to proxy to a particular URI would be great, but examples of how to use mod_rewrite, mod_proxy, and/or mod_proxy_balancer to achieve this proxying to a single URI on a weblogic cluster would be extremely helpful as well.

Answer

Turns out there was an apache feature (Passthrough) I was not aware of (or at least how exactly it works) that can bridge Apache rewrite rules to the weblogic plugin nicely.

RewriteRule /newSection/.*$ /SPA.jsp  [PT,L]

The passthrough rewrites the URI to http://host/SPA.jsp WITHOUT doing a rewrite. The passthrough then explicitly passes that new URI back through the rule stack and other modules. At this point the original weblogic plugin rule I had that proxies by MIME type to the cluster (*.jsp) will pick up the URI and work nicely.

This way Apache takes care of rewriting a set of paths to a specific URI, and the weblogic plugin nicely takes care of the rest (proxying to cluster, load balancing, sticky sessions, etc.)

Comments