Estándar

Configuring Embedded Tomcat in Grails Development Environment

While you are developing a grails app, by default you are using an embedded Tomcat instance.

Sometimes you’ll need to do some configuration, in my case I had to proxy my tomcat instance with an Apache web server through mod_proxy_ajp .

When you have a standalone server running, you can easily change your server.xml file to add an AJP conector which listens for the Apache connections.

To do this within your grails app simply create a _Events.groovy file in your scripts folder of the grails project, and add the configurations needed by your app to the tomcat instance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import grails.util.GrailsUtil
import org.apache.catalina.connector.Connector
import org.apache.coyote.http11.Http11AprProtocol
 
eventConfigureTomcat = {tomcat ->
if (GrailsUtil.environment == 'development')
{
def ajpConnector = new Connector("org.apache.coyote.ajp.AjpProtocol")
ajpConnector.port = 8009
ajpConnector.protocol = "AJP/1.3"
ajpConnector.redirectPort = 8443
ajpConnector.enableLookups = false
ajpConnector.setProperty("redirectPort", "8443")
ajpConnector.setProperty("protocol", "AJP/1.3")
ajpConnector.setProperty("enableLookups", "false")
tomcat.service.addConnector ajpConnector
println "Configured Tomcat ajp connector on port 8009"
}
}

You can also add other tomcat configuration such as Tomcat users and roles: link