Dam*_*che 0 ruby-on-rails apache2 ruby-on-rails-3
我在本地运行我的登台服务器使用:
RAILS_ENV=staging rails console -p 1337
Run Code Online (Sandbox Code Playgroud)
我有预编译资产,一切正常,但我无法找到如何提供这些资产.我在staging.rb中有这个:
config.serve_static_assets = false
Run Code Online (Sandbox Code Playgroud)
在我的apache vhost中,如果我在80上听,我可以访问我的资产:
http://domain.local/assets/application.css
Run Code Online (Sandbox Code Playgroud)
但是,如果我在1337上听,与我的rails服务器相同的端口,那么rails会吐出404.我的困惑是,我已经告诉rails不要发送给serve_static_assets,那么为什么要尝试为它们服务呢?
http://domain.local:1337/assets/application.css
Run Code Online (Sandbox Code Playgroud)
我肯定错过了什么.该网站显示正常,只返回所有资产404:
ActionController::RoutingError (No route matches [GET] "/assets/application-791b26264f9bbe462a28d08cf9a79582.css"):
Run Code Online (Sandbox Code Playgroud)
当您通过访问您的应用程序时
http://domain.local:1337/
Run Code Online (Sandbox Code Playgroud)
你没有通过Apache.
如果你只想使用WEBrick(RAILS_ENV = staging rails s -p 1337)运行它,那么你应该设置
config.serve_static_assets = true
Run Code Online (Sandbox Code Playgroud)
在你的staging.rb中.这将使WEBrick在您访问应用程序时提供预编译资产
http://domain.local:1337
Run Code Online (Sandbox Code Playgroud)
为了使用Apache提供的预编译资产,您应该考虑将Apache(或Nginx)与Ruby模块(如Phusion Passenger)结合使用.然后,您将能够通过访问您的应用程序
http://domain.local
Run Code Online (Sandbox Code Playgroud)
这将使Apache为您的资产提供服务,并将所有其他请求转发给该模块.你可以在这里阅读更多相关信息