# Running JRuby behind an Apache server

**URL:** <https://rubytalk.org/t/running-jruby-behind-an-apache-server/53051>\
**Category:** ruby-talk\
**Created:** [25 April 2009 14:14 UTC](https://rubytalk.org/t/running-jruby-behind-an-apache-server/53051 "2009-04-25T14:14:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [25 April 2009 14:14 UTC](https://rubytalk.org/t/running-jruby-behind-an-apache-server/53051/1 "2009-04-25T14:14:41Z")

</div>

In case anyone's interested, I've started a simple HOWTO blog post for serving up JRuby + {Rails,Merb,etc} if you already have an Apache server (which I suspect is a typical setup for most folks serving Rails and friends):

> **[Apache + JRuby + Rails + GlassFish = Easy Deployment!](http://blog.headius.com/2009/04/apache-jruby-rails-glassfish-easy.html)**
>
> It occurred to me today that a lot of people probably want a JRuby deployment option that works with a front-end web server. I present for y...

I'm no Apache expert, so I'd really love suggestions, but basically it's as simple as running the app in JRuby (using GlassFish gem or Mongrel or whatever) and setting up Apache to proxy to it. JRuby side will handle all requests thrown at it.

- Charlie

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [25 April 2009 14:25 UTC](https://rubytalk.org/t/running-jruby-behind-an-apache-server/53051/2 "2009-04-25T14:25:03Z")

</div>

Do you have any experience with integration in Java based webservers (Tomcat, Jetty and the like)?

Cheers

&nbsp;&nbsp;robert

> **···**
>
> On 25.04.2009 16:14, Charles Oliver Nutter wrote:
> 
> > In case anyone's interested, I've started a simple HOWTO blog post for serving up JRuby + {Rails,Merb,etc} if you already have an Apache server (which I suspect is a typical setup for most folks serving Rails and friends):
> > 
> > [Apache + JRuby + Rails + GlassFish = Easy Deployment! – Charles Oliver Nutter – Java, Ruby, and JVM guy trying to make sense of it all](http://blog.headius.com/2009/04/apache-jruby-rails-glassfish-easy.html)
> > 
> > I'm no Apache expert, so I'd really love suggestions, but basically it's as simple as running the app in JRuby (using GlassFish gem or Mongrel or whatever) and setting up Apache to proxy to it. JRuby side will handle all requests thrown at it.
> 
> --  
> remember.guy do |as, often| as.you\_can - without end  
> [http://blog.rubybestpractices.com/](http://blog.rubybestpractices.com/)

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [25 April 2009 14:43 UTC](https://rubytalk.org/t/running-jruby-behind-an-apache-server/53051/3 "2009-04-25T14:43:21Z")

</div>

Robert Klemme wrote:

> > In case anyone's interested, I've started a simple HOWTO blog post for serving up JRuby + {Rails,Merb,etc} if you already have an Apache server (which I suspect is a typical setup for most folks serving Rails and friends):
> > 
> > [Apache + JRuby + Rails + GlassFish = Easy Deployment! – Charles Oliver Nutter – Java, Ruby, and JVM guy trying to make sense of it all](http://blog.headius.com/2009/04/apache-jruby-rails-glassfish-easy.html)
> > 
> > I'm no Apache expert, so I'd really love suggestions, but basically it's as simple as running the app in JRuby (using GlassFish gem or Mongrel or whatever) and setting up Apache to proxy to it. JRuby side will handle all requests thrown at it.
> 
> Do you have any experience with integration in Java based webservers (Tomcat, Jetty and the like)?

For Apache? Yeah, there's what used to be called mod\_jk, which I believe is now mod\_proxy\_ajp. ajp is a faster-than-proxy protocol that compacts the request and response to speed it up. For something on localhost, however, I doubt it would make much difference for performance to use mod\_proxy\_ajp instead of mod\_proxy\_http.

But yeah, if you wanted to set up a full-on Tomcat or GlassFish or whatever server, you could use the proxy\_http or proxy\_ajp setup just as easily. But I think most people would prefer a single command to run the server process over something like Tomcat.

- Charlie

> **···**
>
> > On 25.04.2009 16:14, Charles Oliver Nutter wrote:

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [25 April 2009 14:55 UTC](https://rubytalk.org/t/running-jruby-behind-an-apache-server/53051/4 "2009-04-25T14:55:02Z")

</div>

> Robert Klemme wrote:
> 
> > > In case anyone's interested, I've started a simple HOWTO blog post for serving up JRuby + {Rails,Merb,etc} if you already have an Apache server (which I suspect is a typical setup for most folks serving Rails and friends):
> > > 
> > > [Apache + JRuby + Rails + GlassFish = Easy Deployment! – Charles Oliver Nutter – Java, Ruby, and JVM guy trying to make sense of it all](http://blog.headius.com/2009/04/apache-jruby-rails-glassfish-easy.html)
> > > 
> > > I'm no Apache expert, so I'd really love suggestions, but basically it's as simple as running the app in JRuby (using GlassFish gem or Mongrel or whatever) and setting up Apache to proxy to it. JRuby side will handle all requests thrown at it.
> > 
> > Do you have any experience with integration in Java based webservers (Tomcat, Jetty and the like)?
> 
> For Apache? Yeah, there's what used to be called mod\_jk, which I believe is now mod\_proxy\_ajp. ajp is a faster-than-proxy protocol that compacts the request and response to speed it up. For something on localhost, however, I doubt it would make much difference for performance to use mod\_proxy\_ajp instead of mod\_proxy\_http.

No no, I meant, using Tomcat, Jetty or the like with JRuby. Sorry, the question was definitively not precise enough.

> But yeah, if you wanted to set up a full-on Tomcat or GlassFish or whatever server, you could use the proxy\_http or proxy\_ajp setup just as easily. But I think most people would prefer a single command to run the server process over something like Tomcat.

Erm, what do you mean by that? With a proper configuration and JRuby's libraries deployed starting Tomcat should be enough. What am I missing?

Kind regards

&nbsp;&nbsp;robert

> **···**
>
> On 25.04.2009 16:43, Charles Oliver Nutter wrote:
> 
> > > On 25.04.2009 16:14, Charles Oliver Nutter wrote:
> 
> --  
> remember.guy do |as, often| as.you\_can - without end  
> [http://blog.rubybestpractices.com/](http://blog.rubybestpractices.com/)

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [25 April 2009 15:12 UTC](https://rubytalk.org/t/running-jruby-behind-an-apache-server/53051/5 "2009-04-25T15:12:48Z")

</div>

Robert Klemme wrote:

> No no, I meant, using Tomcat, Jetty or the like with JRuby. Sorry, the question was definitively not precise enough.

Well, they both work great as far as I know. In Tomcat's case, you would use Warbler to package up your app as a .war file and then deploy that. I believe Jetty can work the same way, though there's also a jetty\_rails gem that's similar to the glassfish gem.

> Erm, what do you mean by that? With a proper configuration and JRuby's libraries deployed starting Tomcat should be enough. What am I missing?

Well, managing a Tomcat instance isn't as simple as just running one command. With JRuby you have exactly \*one\* process for your whole app, and if you can run Rails with config.threadsafe! enabled, you have exactly \*one\* JRuby instance within that process. Just about as easy as it gets.

Maybe it's worth showing the steps to run JRuby behind Apache here:

Prerequisites:

1. Apache with mod\_proxy\_http enabled (sudo a2enmod proxy\_http on Ubuntu). Every default apache I know ships with mod\_proxy\_http.  
2. Java (on Debian/Ubuntu)sudo apt-get install sun-java6-jdk or the openjdk flavors if you like)  
3. JRuby (download, unpack, put bin/ in PATH)  
4. gems appropriate to run your app with JRuby (e.g. rails, activerecord-jdbcsqlite3-adapter, etc)  
5. production DB all set to go

Once you have that, the remaining set up is trivial:

1. Install the glassfish gem (or you can use Mongrel too...see my post):

&nbsp;&nbsp;&nbsp;gem install glassfish

2. From your application directory, run glassfish with these options:

&nbsp;&nbsp;&nbsp;glassfish -p \<port\> -e production -c \<context\> -d

3. Add ProxyPass and ProxyPassReverse lines to Apache (whereever is appropriate on your system) for the GlassFish server instance. For example, if \<port\> is 9000 and \<context\> is foo:

&nbsp;&nbsp;&nbsp;ProxyPass /foo [http://localhost:9000/foo](http://localhost:9000/foo)  
&nbsp;&nbsp;&nbsp;ProxyPassReverse /foo [http://localhost:9000/foo](http://localhost:9000/foo)

4. Reload Apache config, however is appropriate for your system

That's it!

- Charlie
