Running passenger with multiple different ruby versions apache nginx rvm

It’s becoming more and more of a requirement to run different apps under different versions of ruby
One one project I have needed to take the plunge with Ruby 1.9 for unicode support.

This is no big deal really because Passenger and Rails 3 are pretty stable on Ruby 1.9, however, I still have apps that need 1.8 for various reasons I wont go into.

As it stands, Passenger does not support running apps under different interpreters using the apache or nginx modules, I came across this article

I’m going to try and simplify by just giving installation instructions, but if you want a bit more in-depth info as to the reason for this process head on over to Phusion’s blog.

First of all your going to need RVM and passenger module installed on your apache/nginx instance, I’m going to assume you’ve already got this working and the reason your here is to use multiple different versions of the ruby interpreter with passenger.
NOTE: You should be using the interpreter used for the majority of your apps as the base apache or nginx passenger ruby

Lets assume we already have a working app using passenger with ruby 1.8.7 and we want to get another app running but using ruby 1.9.2

So here’s our basic configuration:

1
2
3
4
5
6
7
8
9
10
11
12
# Basic Apache configuration
PassengerRuby /home/user/.rvm/wrappers/ruby-1.8.7-p330/ruby

<VirtualHost *:80>
  ServerName foo.com
  DocumentRoot /home/user/apps/foo.com/public
</VirtualHost>

<VirtualHost *:80>
  ServerName bar.com
  DocumentRoot /home/user/apps/bar.com/public
</VirtualHost>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Basic Nginx configuration
passenger_ruby /home/user/.rvm/wrappers/ruby-1.8.7-p330/ruby

server {
    listen 80;
    server_name www.foo.com;
    root /home/user/apps/foo.com/public;
    passenger_enabled on;
}

server {
    listen 80;
    server_name www.bar.com;
    root /home/user/apps/bar.com/public;
    passenger_enabled on;
}

Now lets setup bar.com so that it’s using the ruby 1.9.2 interpreter

# setup 1.9.2 and run passenger standalone
$ rvm install ruby-1.9.2 # if you don't already have it
$ rvm use 1.9.2
$ cd /home/user/apps/bar.com
$ passenger start -a 127.0.0.1 -p 3000 -d

Update our web server config to use proxy pass

1
2
3
4
5
6
7
8
# Updated Apache configuration
<VirtualHost *:80>
    ServerName www.bar.com
    DocumentRoot /home/user/webapps/bar.com/public
    PassengerEnabled off
    ProxyPass / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
1
2
3
4
5
6
7
8
9
10
# Updated Nginx configuration
server {
    listen 80;
    server_name www.bar.com;
    root /home/user/webapps/bar.com/public;
    location / {
        proxy_pass http://127.0.0.1:3001;
        proxy_set_header Host $host;
    }
}

Deploying your app, bundle and reload your apache or nginx instance.
Then point your browser to `bar.com` If you’ve followed all the steps, you’ll have foo.com using 1.8.7 and bar.com using 1.9.2

3 thoughts on “Running passenger with multiple different ruby versions apache nginx rvm

  1. Howdy very nice web site!! Man .. Beautiful ..
    Superb .. I will bookmark your site and take the feeds also?

    I’m glad to find numerous useful information right here within the put
    up, we need develop extra strategies in this regard, thanks for
    sharing. . . . . .

Leave a Comment