Search code examples
apachetomcatgrailsajp

apache ajp configuration for grails application


I have multiple grails application running on a tomcat server, using the ajp protocol. On the same server I have apache running as a front end to those tomcat applications. apache configuration like this:

ProxyPass /example1/ ajp://localhost:8082/example1/
ProxyPassReverse /example1/ ajp://localhost:8082/example1/
ProxyPass /example2/ ajp://localhost:8082/example1/
ProxyPassReverse /example2/ ajp://localhost:8082/example2/

I want example1 to run as the root context

ProxyPass / ajp://localhost:8082/example1/

this does not work. All Static content is broken. the web page text renders, by the images would point to: /example1/images/myimage.jpg the image would get resolved if you go to: /images/myimage.jpg

I have tried many things to avoid deploying example1 as ROOT.war. but that seems to be the only way to resolve this issue. This is not sufficient for my need.

on the grails side, I've tied removing the ${appName} from the server url, to look like: grails.serverURL = "http://apacheajp.example.com/"

I've added grails.app.context=/ to application.properties, this did not work either.

the ultimate goal here is to use this apache to server for multiple subdomains. I would want example1.example.com (a alias to apacheajp.example.com) to resolve to the example1 app. Similarly, I would want example2.example.com to act the same way for the example2 app. This explains why deploying as ROOT would be undesirable.

the server I use is RHEL6

this post here best describes the same issue I am having: http://grails.1312388.n4.nabble.com/Grails-context-big-problem-with-apache-mod-proxy-td1392448.html


Solution

  • As Mark Thomas suggest, it's easiest to deploy your application with the same context root on Tomcat as you want it to have on Apache. So for context root '/' this means to deploy as ROOT.war on Tomcat. To have multiple apps with context root '/' but different subdomains, the easiest solution is probably to run multiple instances of Tomcat, one for each application, and deploy all of them as ROOT.war. This is how we do it. This also means it's easier to do upgrades without taking down all applications.

    Each Tomcat instance will need its own shutdown port, http port and ajp port in conf/server.xml.