Rails 3.1, nginx, Passenger directory index forbid

2020-02-09 03:33发布

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?

4条回答
smile是对你的礼貌
2楼-- · 2020-02-09 03:49

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.

查看更多
我想做一个坏孩纸
3楼-- · 2020-02-09 03:55

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.

查看更多
Fickle 薄情
4楼-- · 2020-02-09 03:58

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;
查看更多
时光不老,我们不散
5楼-- · 2020-02-09 04:10

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.

查看更多
登录 后发表回答