Monday, March 21, 2011

Fronting Eclipse Jetty server with Apache and mod_proxy

Lately I have been developing apps for App Engine and I use Eclipse with the Google Plugin for Eclipse. This means my development server in Eclipse is Jetty. In a previous post, I described how I used an apache server (with a “real” SSL certificate, etc.) to front my development machine for part of my development process. I used mod_jk to connect to my Tomcat server in eclipse.

But with the Google plugin for Eclipse, the server is Jetty – not Tomcat.  Jetty does permit a mod_jk connection, and I would have preferred to do this since I already knew how to do it. However, I could not find the Jetty config file, or otherwise control the parameters of Google’s Jetty instance. (I even asked the community…)

Further reading suggested that I should avoid mod_jk with Jetty anyhow. This particular page suggested that I use mod_proxy to do what I wanted. So I had some homework to do on mod_proxy. I knew the architecture would be the same as before, just with mod_proxy:


After reading the Apache mod_proxy docs, I learned that what I want is referred to as a “reverse proxy” in their language. This is where you configure an public apache server to forward certain requests to specific backend servers. There are a variety of applications possible, like load balancing, and caching, etc. But all I needed was the simplest use case. I was quite relieved that setting this up was straightforward. The biggest hurdle in my case was the fact that I had to rebuild apache with the right options to include mod_proxy_http, which was not originally compiled on my box.

I had to add these entries to my httpd.conf:

LoadModule proxy_http_module libexec/apache22/



# turning on a "reverse proxy" to reach the Jetty server on my dev box during development.
# read about it here:
ProxyPass /dev
ProxyPassReverse /dev


Lucky me. Loading http://mysite.domain/dev gave me content from my dev server. Happy day!

Note: the same caveats apply regarding cookies and domains. There are some additional apache directives, ProxyPassReverseCookieDomain, and ProxyPassReverseCookiePath to help rewrite those values, if you are setting them.

No comments:

Post a Comment