Modular Sinatra app returns 404's under Passenger

I have a modular Sinatra app which runs fine when executed with rackup. The config.ru file is defined as follows:

map '/' do
  run My::Controllers::Default
end

map '/api' do
  run My::Controllers::Api
end

When I run the app under nginx/passenger I get nothing but 404's, even for the '/' route. Suspecting that something was wrong with routing, I modified config.ru as follows:

run My::Controllers::Default

After restarting nginx, I was served the default page of the app. However, the default page of the app reaches into the api route to get some documentation to display, and that part returns a 404. Given that config.ru is able to run the Default controller, I'm sure that the issue has nothing to do with being able to load all of the relevant ruby files--which seems to be the problem in other related questions I've found on SO.

With that in mind I modified config.ru as follows:

map '/api' do
  run My::Controllers::Api
end

run My::Controllers::Default

At this point I'm back to getting nothing but 404's, even for the '/' route. It seems that the map statement is confusing the webserver and making it unable to find the correct routes.

If I just run the app using rackup everything behaves as expected, so I'm really at a loss to explain what I'm seeing.


I remember this being the answer. Let me know if it works for you. If it does I'll "Accept" the answer so that others will find it.

Middleware

A bug in passenger prevents it from understanding the map statement in config.ru https://groups.google.com/forum/#!msg/phusion-passenger/PoEEp9YcWbY/1y0QL_i3tHYJ

class PassengerFix

  def initialize(app)
    @app = app
  end

  def call(env)
    env["SERVER_NAME"] = env["HTTP_HOST"]
    return @app.call(env)
  end

end

config.ru

configure do
  use PassengerFix
end
链接地址: http://www.djcxy.com/p/32536.html

上一篇: 使用Sinatra获得Rack GemNotFound

下一篇: Modular Sinatra应用程序在Passenger下返回404