How i learned to stop worrying and love apache . . .
Ok, maybe not:-
Tomcat has a slightly annoying habit of the following, if you make the following request:-
$ telnet localhost 8080 GET /webapp/foo.jsp HTTP/1.0 Host: localhost
The objects that are returned contain the following HTML:-
This is not a good thing when delivered to the web browser, so there’s a few ways to fix:
- Use some “magic” to display FQDNs (yuck)
- Use JkMount (aka old fashioned mod_jk)
- Use mod_proxy_ajp
The following code fragment would work for Mod_jk
JkMount /webapp2 worker1
JkMount /webapp2 worker2
RewriteEngine on
RewriteCond {REQUEST_URI} !=/images
RewriteCond {REQUEST_URI} !=/css
RewriteCond {REQUEST_URI} !=/swf
RewriteRule . /webapp2${REQUEST_URI}
Or using the “newer” mod_proxy_ajp
ProxyPass /images ! ProxyPass /css ! ProxyPass /swf ! ProxyPass / ajp://localhost:8080/webapp1 ProxyPassReverse / http://localhost:8080/webapp1
If you want to keep using the simpler mod_proxy_html module to map through to tomcat and still “hide” your web application mount name, you can use tomcat virtualhosting and then just
ProxyPass /images !
. . .
ProxyPass / http://servername:8080/
ProxyPassReverse / http://servername:8080/
The following is how to add virtualhosting to tomcat (I’m not a big fan of this as it spreads more configuration around when creating and managing sites)
===server.xml===
<Host name="$host"
debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="$host\_log." suffix=".txt" timestamp="true"/>
<Alias>$alias</Alias>
<Context path="" docBase="webapps/$host" debug="0" reloadable="true"/>
</Host>