Rails 3.1, nginx, Passenger directory index forbidden
Asked Answered
C

4

14

I'm getting the following error in nginx (with a 403) when I visit .com:

[error] 5384#0: *1 directory index of "/u/apps/<app-name>/current/public/" is forbidden

I'm on Ubuntu 10.04 and I can't for the life of me get nginx, Passenger, Rails 3.1, and Capistrano to play nicely.

I'm deploying to /u with Capistrano. Everything in /u is 755, owned by the app user.

/u/apps//current/public/ has all my assets, the favicon, and everything else you'd expect.

When I add autoindex on to nginx.conf I get a listing of the public/ directory, which leads me to believe that I don't have a permission problem.

My nginx.conf file is default expect for:

server {
    listen 80;
    server_name <app-name>.com;
    passenger_enabled on;
    root /u/apps/<app-name>/current/public/;
}

And my Capistrano deploy.rb file has nothing unusual.

Any ideas why the rails app doesn't seem to be starting?

Cup answered 15/11, 2011 at 5:13 Comment(0)
C
29

Alright, I answered my own question. I was missing passenger_ruby and passenger_root configurations in my nginx.conf file. Note that the passenger_ruby path needs to be the wrapper if you're using RVM.

passenger_root /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.9;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p290/ruby;
Cup answered 15/11, 2011 at 19:54 Comment(3)
Well, if this solved your problem, go ahead and accept your own answer.Fourposter
Any idea why it has to be the wrappers ? I don't really know what are the different directories about in RVM but why not bin instead ?Negative
This happens if Passenger can't be loaded for any reason. If the path is wrong, you see the same result.Lowboy
B
11

If you already have passenger_root and passenger_ruby in your nginx.conf, but having this error, you must have some location blocks. Then you must specify passenger_enabled on; inside each location block.

Brutify answered 12/11, 2012 at 6:5 Comment(3)
This dig the trick for me, I forgot to add the passenger_enabled on to the sites configuration.Confinement
Not true in my case. I have no location blocks, but I still get this error.Arium
I had no location blocks either so I added a location / { passenger_enabled on; }Olnton
M
9

In case you are running into this with Passenger 5+ and your Rails app is a 2.3.x app, you now need to add a config.ru file to your app:

# Require your environment file to bootstrap Rails
require ::File.dirname(__FILE__) + '/config/environment'

# Serve static assets from RAILS_ROOT/public directory
# use Rails::Rack::Static
# Dispatch the request
run ActionController::Dispatcher.new  

More details in the official announcement and github ticket.

I know the OP's question was about Rails 3.1 specifically but wanted to include this here since the output is identical and searches led me to this post.

Matz answered 15/6, 2016 at 18:52 Comment(1)
Spent 3 hours looking for this! Many kudos. Thanks!!Rea
N
4

Sorry to answer to an old question, but it seems relevant (at least for me ;-) ) I had a similar problem and manage to solve it thanks to this post but in a different way. Alternatively, you can setup the /etc/nginx/nginx.conf to use:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;

And then make sure the locations.ini is current by running:

passenger-config --make-locations-ini

As said, this worked for me, though I'm not an expert, maybe I'm playing with the wrong parameters.

Nitza answered 4/10, 2013 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.