Friday, August 20, 2010

Quick Apache/Tomcat Proxying Tip

I'm setting up some new servers with some semi-complex URL rewriting and proxying going on of both the HTTP and AJP varieties. For this particular application the home page is actually a completely separate application that's running as its own webapp on Tomcat, and everything else runs from within the webapp itself. (I'll spare you the details; just assume I'm not insane and this was the best way to handle this situation.)

So for all this to work properly I have the following rewrite rule:

RewriteRule ^/$ http://otherapp/ [NC,P]
ProxyPassReverse / http://otherapp/


Then below that I have a bunch of AJP rewrites for the webapp itself. What was throwing me fits was that everything was working great except for this one rewrite rule, which would attempt to load indefinitely until I killed the request.

I stared at my virtual host config file for quite a while and finally paused on this line:

ProxyPreserveHost On


Given that the ^/$ rewrite rule is proxying out to a different host, it seems kind of obvious now that of course that would confuse Apache. Removing that line and adding some aliases for the other host's CSS and images directory did the trick.

Maybe no one else will be in this exact situation, but if you're ever faced with a blank white screen while waiting forever for an HTTP proxy to go through, this tip might come in handy.

No comments: