简体   繁体   English

乘客问题:“没有可以加载的文件”——/config/environment

[英]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:我已经安装了乘客 (2.2.11) 和 nginx (0.7.64),当我启动并点击 Rails URL 时,我收到一个错误页面,通知我加载错误:

no such file to load -- /path/to/app/config/environment没有要加载的文件 -- /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.从我在网上找到的内容来看,这似乎是某种用户/权限错误,但我已经尝试了所有逻辑修复:我已经确保 /config/environment.rb 不是由 root 拥有的,而是由webapp 用户。 I've tried setting passenger_default_user, I've tried setting passenger_user_switching off.我试过设置passenger_default_user,我试过设置passenger_user_switching。 I've even tried setting the nginx user, though that shouldn't matter much.我什至尝试过设置 nginx 用户,但这应该没什么关系。 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;我可能会尝试退回到更早版本的Passenger,因为我以前从未遇到过这个问题; it's been a little while since I set up Passenger though.不过我已经有一段时间没有设置乘客了。

Thanks for any suggestions.感谢您的任何建议。

EDITED: See below for the answer I stumbled on.编辑:有关我偶然发现的答案,请参见下文。

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 :来自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.此时的关键是确保应用程序文件归 www-data 所有,特别是config/environment.rb因为显然Passenger 会查看其所有者以确定以谁的身份运行。 This might mean that the passenger_default_user entry is irrelevant?这可能意味着passenger_default_user条目无关紧要? 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.最后,确保您的应用程序的父目录都可以通过www-data访问——在我的情况下,系统默认设置留下了一个目录0700 ,我错过了。

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.如果您的 Rails 应用程序中有config.ru ,Passenger 会尝试将其加载为 Rack 应用程序。 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.特别是,您的错误消息涉及config/environment —— 请注意 Rails 应用程序中缺少.rb扩展名。

Try moving config.ru out of the way if it exists.如果存在,请尝试将config.ru

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM