x-yuri
x-yuri

Reputation: 18883

How to make passenger and rvm work together?

I've had rvm installed beforehand. And I decided to install passenger from a package (nginx-full and passenger) and would like to use the ruby installed with rvm. But somehow it doesn't work. Here's the test sinatra app I'm using (~yuri/a1/app.rb):

require 'rubygems'
require 'sinatra'

get '/' do
  "Hello and Goodbye"
end

~yuri/a1/config.ru:

require 'rubygems'
require 'sinatra'

require './app.rb'
run Sinatra::Application

nginx.conf:

http {
    ...
    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
        # the paths in the above file point out to debian repository's ruby version
    server {
        server_name a1;
        root   /home/yuri/a1;
        access_log   /var/log/nginx/a1-access.log;
        error_log   /var/log/nginx/a1-error.log;
        passenger_enabled   on;
        passenger_ruby   /home/yuri/.rvm/wrappers/ruby-1.9.3-p385@a1/ruby;
    }
}

But when I do w3m http://a1 access.log says:

127.0.0.1 - - [12/Sep/2013:21:14:58 +0300] "GET / HTTP/1.0" 403 168 "-" "w3m/0.5.2+cvs-1.1027"

and error.log:

2013/09/12 21:14:58 [error] 27622#0: *1 directory index of "/home/yuri/tr/" is forbidden, client: 127.0.0.1, server: tr, request: "GET / HTTP/1.0", host: "a1"

The app works if I run it as follows: rvm ruby-1.9.3-p385@a1 && ruby app.rb.

Is there a way to track down what's happening there? Or how to make it work?

Upvotes: 0

Views: 2776

Answers (2)

x-yuri
x-yuri

Reputation: 18883

passenger expects application directories to have a certain layout. Particularly, config.ru must reside up one level relative to the document root. That is:

/etc/nignx/nginx.conf:

...
http {
    ...
    passenger_root   /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    server {
        server_name a1;
        root   /home/yuri/a1/public;
        access_log   /var/log/nginx/a1-access.log;
        error_log   /var/log/nginx/a1-error.log;
        passenger_ruby   /home/yuri/.rvm/wrappers/ruby-1.9.3-p385@a1/ruby;
        passenger_enabled   on;
    }
}

~yuri/a1/app.rb:

require 'sinatra'
get '/' do
  "Hello World!"
end

~yuri/a1/config.ru:

require './app'
run Sinatra::Application

And:

$ rvm install 1.9.3-p385
...
$ rvm --create use 1.9.3-p385@a1
...
$ curl http://a1
Hello World!

Upvotes: 5

ajaya
ajaya

Reputation: 21

I just went through setting up passenger 4.0.17 on Ubuntu Precise using the apt approach.

Here is what worked for me.

In the /etc/nginx/nginx.conf

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby;

Try moving the passenger_ruby to outside of the server block.

Good Luck

Upvotes: 2

Related Questions