如何让乘客和车辆一起工作?

时间:2013-09-12 18:22:47

标签: ruby nginx sinatra rvm passenger

我事先安装了rvm。我决定从一个软件包(nginx-full and passenger)安装乘客,并希望使用rubyrvm一起安装。但不知怎的,它不起作用。这是我使用(sinatra)的测试~yuri/a1/app.rb应用:&/ p>

require 'rubygems'
require 'sinatra'

get '/' do
  "Hello and Goodbye"
end

〜梨/ 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;
    }
}

但当我w3m http://a1 access.log说:

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

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"

如果按以下方式运行该应用程序:rvm ruby-1.9.3-p385@a1 && ruby app.rb

有没有办法追踪那里发生的事情?或者如何让它发挥作用?

2 个答案:

答案 0 :(得分:5)

passenger期望应用程序目录具有某个layout。特别是,config.ru必须相对于文档根位于一个级别。那就是:

/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;
    }
}

〜梨/ A1 / app.rb:

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

〜梨/ A1 / config.ru:

require './app'
run Sinatra::Application

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

答案 1 :(得分:2)

我刚刚使用apt方法在Ubuntu Precise上设置了乘客4.0.17。

这对我有用。

在/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;

尝试将passenger_ruby移动到服务器块之外。

祝你好运