1

我正在使用以下方法在本地运行我的登台服务器:

RAILS_ENV=staging rails console -p 1337

我已经预编译了资产,一切正常,除了我不知道如何为这些资产提供服务。我在我的 staging.rb 中有这个:

config.serve_static_assets = false

在我的 apache vhost 中,如果我在 80 上收听,我可以访问我的资产:

http://domain.local/assets/application.css

但是,如果我在 1337(与我的 rails 服务器相同的端口)上监听,那么 rails 会吐出 404。我的困惑是,我已经告诉 rails 不要为它们提供服务,那么它为什么要尝试为它们服务呢?

http://domain.local:1337/assets/application.css

我肯定错过了什么。该站点显示正常,仅对所有资产返回 404:

ActionController::RoutingError (No route matches [GET] "/assets/application-791b26264f9bbe462a28d08cf9a79582.css"):
4

1 回答 1

5

当您通过以下方式访问您的应用程序时

http://domain.local:1337/

你没有通过 Apache。

如果您只想使用 WEBrick (RAILS_ENV=staging rails s -p 1337) 运行它,那么您应该设置

config.serve_static_assets = true

在您的 staging.rb 中。当您通过以下方式访问应用程序时,这将使 WEBrick 为预编译资产提供服务

http://domain.local:1337

为了使用 Apache 提供的预编译资产,您应该考虑将 Apache(或 Nginx)与 Ruby 模块(如 Phusion Passenger)结合使用。然后您将能够通过以下方式访问您的应用程序

http://domain.local

这将使 Apache 为您的资产提供服务,并将所有其他请求转发到模块。您可以在此处阅读有关此内容的更多信息

于 2012-09-11T02:36:16.607 回答