mod_proxy and mod_rewrite

Just spent a part of the day reading the docs and playing, and have come to the conclusion that mod_proxy and mod_rewrite are simpler to set up than jk, jk2 or mod_webapp and just as effective, if not more so, because you're not tied to using Tomcat (well, Jetty has a JK adapter too, but *shhh*)

For those of you out there looking to see how it's done, take a look at the Proxy Support HOWTO over at the Jakarta site. Use this technique when you need to pass through whole sub-directories to your app server (take a look at your servlet-mappings in the web.xml file --- it should be obvious)

Where you have a servlet mapping that matches a postfix (such as "*.jsp") you'll need to write a mod_rewrite rule that redirects that URL to the proxy. For example, I am currently using:

RewriteRule ^/(.*\.jsp.*)   http://localhost:8080/$1  [P,L]

to pass any requests for JSPs to the localhost, and this seems to do the trick.

BTW, I assume that I have to match after the postfix in case the JSESSIONID is appended to it. If I'm deluded or just plain wrong, can someone please comment?


Simon Stewart on Thursday, 23 January, 2003

Posted in: /computing /java /work

You may comment...



Added by Chris Winters on Friday, 24 January, 2003

Something to also remember: stick a:

ProxyPassReverse / http://127.0.0.1/

or

ProxyPassReverse / http://localhost/

in there, otherwise URLs returned to the user may have the :8080 on the end, which botches everything up.

Added by Simon Stewart on Friday, 24 January, 2003

Thanks for that! After reading the docs I hadn't noticed that this was a useful thing to do. I've added it to my config.

The other thing that I've done is not compile mod_proxy into Apache. This means that I only need to LoadModule the bits that I care about, and not (for example) mod_proxy_connnect.

Categories