我注意到,当 serve_static_assets
设置为 false 时,heroku 会在 Cedar 上注入(inject) rails3_serve_static_assets
中间件。我对此的所有发现是 this init script与 Heroku 部署中提到的名称相匹配,它所做的一切都是重新启用静态 Assets 的服务。
我正在尝试查找有关 Heroku 如何提供这些资源的更多信息,因为它们似乎并非直接来自 Rails 应用程序。
例如,当我查看 js 文件的 header 时,它们看起来像这样:
Age:0
Connection:close
Content-Encoding:gzip
Content-Type:text/css
Date:Sun, 08 Jan 2012 19:04:05 GMT
Last-Modified:Sat, 07 Jan 2012 23:43:30 GMT
Server:nginx/0.7.67
Transfer-Encoding:Identity
Via:1.1 varnish
X-Varnish:677359987
我假设 Via:1.1 varnish
意味着这些资源是通过 Varnish 提供的,但是 the online documentation 。就此事表示 Varnish 在 Cedar 上不可用。
Cedar docs在 gzipped 响应(底部)中指出:
Since requests to Cedar apps are made directly to the application server – not proxied through an HTTP server like nginx – any compression of responses must be done within your application.
但是我们可以清楚地看到该资源是根据 Content-Encoding
进行 gzip 压缩的。现在我相当确定 Rails 3.0.x 没有启用 Rack::Deflater
(它不会出现在 rake middleware
中)无论如何)所以我有点困惑这个 Assets 是如何被 gzip 的。
这有点像 my next question 的前体关于通过 Cloudfront 提供这些 Assets ,但我的问题是:
有人可以准确解释一下 Cedar re: 静态 Assets 上发生的情况吗?也就是说,什么为我的 Assets (Rails、Ngnix、Varnish??)提供服务,以及对它们进行 gzip 处理?
最佳答案
如果您在 header 中看到 Varnish,则意味着您的域名 CNAME 指向 proxy.heroku.com 而不是 proxy.herokuapp.com - Cedar 上没有 Varnish,但如果您使用,您将看到返回的 header proxy.heroku.com 并且它可以工作,但它只是一个传递。它们将由 nginx 提供服务。
关于ruby-on-rails-3 - Heroku Cedar - 静态 Assets - Rails 3.0.x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8781039/