Grails 1.1.1 on Tomcat 6 with root ( "/" ) application
I've had a bit of trouble getting Grails installed on Tomcat as I wanted, so time to share the pain.
The reason for deploying to Tomcat rather than is around proxying of requests via Apache. First, I need to use Apache as a proxy to allow for sharing of IP addresses across virtual hosts. This is so I don't waste bunches of IP addresses going direct to Apache for static hosting plus various Tomcat/other JEE instances for applications. I want to run mutiple JEE server instances (whether Jetty, Glassfish or Tomcat), so that restarting a server doesn't impact other services I'm running. And in the future, I may want to load balancer across multiple backend servers.
With Apache and Jetty, I've found significant performance issues doing proxying with mod_proxy_ajp. From the Jetty website (http://docs.codehaus.org/display/JETTY/Configuring+AJP13+Using+mod_jk), "Some tests have shown 15% more throughput with mod_proxy than with mod_ajp", and beyond that, I'm actually getting HTTP 500 Internal Server Error. However, I can't use mod_proxy alone, as it doesn't forward client IP address to the JEE server, which is something I want to capture. Since the Mortbay guys state that "the AJP protocol is poorly documented and there are many version irregularities", then I thought it best to go with the people who created it, hence the decision for Tomcat.
So back to Grails on Tomcat, initial implementation is easy, just following the standard Tomcat documentation, and dropping the WAR file into the {tomcat-home}/webapps. However, I want to have my application listen to the root context - i.e. http://mydomain.com/, without the war file name on the context path (e.g. http://mydomain.com/myapp).
So in Grails, the first step is to edit the grails-app/conf/Config.groovy, and add the following line:
grails.app.context = "/"
Then, we need to fix Tomcat. After much trawling Tomcat documentation, I found this: http://wiki.apache.org/tomcat/HowTo#head-2e16a614a1be6e03102fc69dd59587a..., Addendum 2, Method 2.1. So you need to
- Place your war file outside of CATALINA_BASE/webapps (it must be outside to prevent double deployment).
- Place a context file named ROOT.xml in CATALINA_BASE/conf/<engine name>/<host name>. The single <Context> element in this context file MUST have a docBase attribute pointing to the location of your war file. The path element should not be set - it is derived from the name of the .xml file, in this case ROOT.xml. See the Context Container above for details.
In my case, this wasCATALINA_BASE/conf/Catalina/localhost/ROOT.xml, which contained:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="" docBase="/usr/local/path/to/my/app.war" antiResourceLocking="false" privileged="true" />
Restart Tomcat, and voila, working application, listening to "/".

Comments
So what did your mod_proxy setup end up looking like? (thanks for this info!)
A couple of other issues - the error document failed, so I made custom ones, and I excluded access to the management tools of Tomcat by specifically barring them. Also note that I've excluded a bunch of stuff from the virtualHost for security reasons.
Post new comment