1

我在生产环境中运行 Rails 服务器,并且预编译了我的资产,但由于某种原因,请求将转到 /assets 目录而不是 /public。

我有默认的 production.rb 文件。这可能是什么原因造成的?

# config/environments/production.rb

config.cache_classes = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.force_ssl = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
4

2 回答 2

1

请求将发送到/assetspublic由应该位于 Rails 应用程序前面的网络服务器从目录中提供。

因为你已经config.serve_static_assets准备好falseconfig/environments/production.rb,Rails 甚至不会尝试为这些资产提供服务。

我建议在 Rails 前面放置一个运行Passenger的 Apache 或 Nginx 服务器,以便 Apache 或 Nginx 为您的应用程序提供资产和代理请求。

于 2012-10-10T04:20:01.797 回答
1

您还可以更改:

config.serve_static_assets = true

然后您的资产将从 /public/assets 提供,而无需使用 Apache 或 Nginx。

对于开发,只需删除 /public/assets 目录,然后它们将自动编译并从 /assets 提供。

于 2012-10-10T05:01:04.573 回答