502在nginx上的sinatra app的Rack应用程序中的错误网关错误/ NameError,在docker容器中的乘客

时间:2015-02-11 21:42:25

标签: nginx sinatra docker passenger

我从docker(1.3.2)开始,我正在尝试使用nginx,乘客和sinatra。 Nginx和乘客似乎都有效。但是,我没有让我的sinatra应用程序运行。当我尝试在浏览器中访问时,curl localhost会出现 502错误的网关错误。问题是为什么会发生这种情况,如果这是与docker相关的还是配置问题?

如果我将index.html放在公开的服务中。如果我使用rackup和curl localhost:9292启动应用程序(见下文),我会收到预期的回复。

nginx error.log显示:

request: "GET / HTTP/1.1", upstream: "passenger:/tmp/passenger.1.0.766/generation-0/request:", host: "localhost"
App 812 stderr: [ 2015-02-09 16:19:54.3173 828/0x00000000b759a8(Worker 1) utils.rb:84 ]: *** Exception NameError in Rack application object (uninitialized constant Rack::MethodOverride::REQUEST_METHOD) (process 828, thread 0x00000000b759a8(Worker 1)):
App 812 stderr:         from /var/lib/gems/2.1.0/gems/rack-1.6.0/lib/rack/methodoverride.rb:14:in `call'
App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'
App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
App 812 stderr:         from /var/lib/gems/2.1.0/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
App 812 stderr:         from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
2015/02/09 16:19:54 [error] 786#0: *9 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: localhost,

Google搜索错误消息我找不到任何有用的信息。我还尝试设置此处描述的示例:https://www.linode.com/docs/websites/frameworks/sinatra-framework-and-nginx-on-debian-6-squeeze 与上述结果相同。

我的目录结构:
    /home/app/sinatra-test/config.ru
    /home/app/sinatra-test/app.rb
    /主页/应用/屈测试/公/
    / etc / nginx / sites-enabled / sinatra-test

config.ru:

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

app.rb:

require 'sinatra'

get '/' do
  "Hello from Sinatra!"
end
在sinatra-test中的

nginx配置:

server {
  server_name localhost;
  listen 80;
  root /home/app/sinatra-test/public;

  passenger_enabled on;
  passenger_user app;
  passenger_ruby /usr/bin/ruby2.1;
}

2 个答案:

答案 0 :(得分:0)

进一步阅读导致这个http://blog.baroquebobcat.com/category/tech/指向了答案 - 安装的机架版本与sinatra所需的不匹配。我正在使用包含机架1.6.0的phusion乘客码头图像。降级至1.4.0解决了这个问题。

答案 1 :(得分:0)

我是Phusion Passenger的作者。我们最近收到了另一位遇到同样问题的用户提出的问题。问题的原因几乎与ikkjo描述的一样。解决方案是使用Gemfile。

我们已在Passenger Github问题跟踪器上记录了该问题及其解决方案:https://github.com/phusion/passenger/issues/1478#issuecomment-93730487