Last Updated: December 07, 2019
·
7.401K
· kevintuhumury

Running Passenger with nginx on multiple Ruby versions with RVM

When you want to deploy multiple Rails applications on a single VPS, you might run into problems when they require different Ruby versions. I've got a quick tip for you to easily enable this.

First of all, I'm going to assume you've already got RVM running on your VPS and installed the passenger module on your nginx instance with:

passenger-install-nginx-module

Now, make sure you've installed Phusion Passenger 4.0.0 or higher, since those versions allow for multiple Ruby versions. I'll also assume you've installed multiple Ruby versions with RVM. Let's say ruby 1.9.3-p545 and ruby 2.0.0-p451.

The Example Rails applications is running on ruby-1.9.3-p545 and the AnotherExample Rails application is running on ruby-2.0.0-p451. All that you've got to add to your nginx .conf file (or files) now are the following server blocks:

server {
  listen 80;
  server_name example.com
  root /var/www/example/current/public;

  passenger_ruby /home/deploy/.rvm/wrappers/ruby-1.9.3-p545/ruby;
  passenger_enabled on;

  ...
}

server {
  listen 80;
  server_name anotherexample.com
  root /var/www/anotherexample/current/public;

  passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.0.0-p451/ruby;
  passenger_enabled on;

  ...
}

That's it!

3 Responses
Add your response

Hi,

Did you forget the passenger_root directive ?
With kind regards.

Michaël

over 1 year ago ·

Yes and no. I didn't include it in the above tip, but I do have it defined in a .conf file.

Maybe I wasn't clear about that, but the above server blocks are located in /etc/nginx/sites-enabled. Besides those files I have a /etc/nginx/conf.d/passenger.conf where the passenger_root directive is defined.

over 1 year ago ·

How does your passenger.conf-file look?
Because you cannot set both in the nginx.conf-file and I have had both passengerruby and passengerruby set in the nginx.conf before.

over 1 year ago ·