Passenger problem: "no such file to load" -- /config/environment
I've been researching this one and found references to similar problems here and there, but none of them has led to a solution yet. I've installed passenger (2.2.11) and nginx (0.7.64) and when I start things up and hit a Rails URL, I get an error page informing me of a load error:
no such file to load -- /path/to/app/config/environment
From what I've found online this appears to be some sort of a user/permissions error, but I've tried all the logical fixes: I've made sure that /config/environment.rb is not owned by root, but by a webapp user. I've tried setting passenger_default_user, I've tried setting passenger_user_switching off. I've even tried setting the nginx user, though that shouldn't matter much. I've gotten some differing results, but nothing's actually worked. I'm hoping someone may have the magical combination of settings and permissions for this. I may try backing down to an earlier version of Passenger, because I've never had this issue before; it's been a little while since I set up Passenger though.
Thanks fo开发者_JS百科r any suggestions.
EDITED: See below for the answer I stumbled on.
Modern Passenger prefers Rack to Rails. If you have a config.ru
in your Rails application, Passenger will try to load it as a Rack application. This may be causing problems. In particular, your error message refers to config/environment
-- note the lack of the .rb
extension typical in a Rails application.
Try moving config.ru
out of the way if it exists.
Naturally, it just took me posting the question to stumble onto the answer. In order to provide info for anyone else searching on this problem, I'll post some details here.
The relevant lines from the nginx.conf
:
user www-data; # in order to have nginx not run as root
passenger_default_user www-data; # likewise for passenger
root /opt/foo/app/current/public;
The key at this point is to make sure that the application files are owned by www-data, in particular config/environment.rb
because apparently Passenger looks at its owner to determine who to run as. This might mean that the passenger_default_user
entry is irrelevant? But it's good to have it there as documentation of intent anyway, perhaps.
Finally, make sure that the parent directories of your app are all reachable by www-data
-- in my case the system default setup had left a directory 0700
, which I'd missed.
精彩评论