Sean Carpenter

Using Passenger Standalone in an Apache Location Element

Using Passenger Standalone and RVM you can run web apps using multiple versions of Ruby on a single server. Phusion has a blog post with fairly detailed instructions on getting this set up.

One assumption in that post is that each web app will be running as its own site (using the ServerName directive inside an Apache <VirtualHost> element). In my case, I wanted to run each web app as a virtual directory in a single VirtualHost. My original configuration (with everything running the same Ruby version) looked like this:

1
2
3
4
5
6
<VirtualHost *:80>
    # Other configuration directives...
    RackBaseURI /app1
    RackBaseURI /app2
    RackBaseURI /app3
</VirtualHost>

This server is using (regular) Passenger to serve 3 Rack apps (in this case Sinatra) at the urls /app1, /app2, and /app3. Now I want to run app1 under a different Ruby version. Following the instructions in Phusion’s post, I installed Ruby 1.9.3 using RVM and then installed Passenger (note: the --pre flag isn’t necessary for installing Passenger anymore since the current release version includes the Standalone server).

The next step is to switch app1 to Ruby 1.9.3 while leaving app2 and app3 alone:

1
2
3
4
5
6
7
8
9
10
<VirtualHost *:80>
    # Other configuration directives...
    RackBaseURI /app2
    RackBaseURI /app3
    <Location /app1>
        PassengerEnabled off
        ProxyPass http://127.0.0.1:3000/
        ProxyPassReverse http://127.0.0.1:3000/
    </Location>
</VirtualHost>

There are only a few changes here. First, app1 has its RackBaseURI directive removed. Secondly, a <Location> element was added for the /app1 virtual directory. On line 6 the PassengerEnabled directive turns off the “main” Passenger processing for this virtual directory. Then the ProxyPass and ProxyPassReverse directives are added to handle the proxying to Passenger Standalone.

With only those few changes, app1 is now running on Ruby 1.9.3 while app2 and app3 continue to run as they did before. If the need arises later to run another version of Ruby it’s just a matter of installing it with RVM, setting up a new instance of Passenger Standalone, and adding another <Location> element.