如何使用 Passenger 和 Apache 设置我的 RAILS_ENV?

How do I set my RAILS_ENV with Passenger and Apache?

我今天到处都在寻找为 Passenger 正确设置 RAILS_ENV 的方法。既然网站在我的服务器上,我想使用测试环境,但我不希望它成为生产环境,因为我遇到了数据库问题。

我被引导至 this part of the documentation,但对我来说没有任何意义。我在网站的 Apache .conf 文件中有 PassengerAppEnv RAILS_ENV = 'test',但正如预期的那样,它不起作用。

我还在我的 Rails 站点的 config/environment.rb 中设置了 RAILS_ENV = 'test',但这也没有用。

谢谢!

你很接近,但不太正确。设置方法如下:

<Directory /path/to/app/public>
Allow from all
Options -Multiviews
# ^ for Apache 2.4+
Require all granted
RailsEnv development # < place desired environment here 
</Directory>

基本上Passenger会在配置文件中看到这一行然后给你设置。它使用更多 Apache 风格的语法:

 Name [space] <value>

因此您根本不需要所有引号或任何 Ruby 样式语法。