接收 - 编码Cloudfront上的标题,从Heroku Cedar的Rails 3.0.x上提供资产 [英] Accept-Encoding headers on Cloudfront serving assets from Rails 3.0.x on Heroku Cedar

查看:218
本文介绍了接收 - 编码Cloudfront上的标题,从Heroku Cedar的Rails 3.0.x上提供资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用我的Rails应用程序通过Heroku的雪松堆栈(即不通过CDN)直接提供资产时,他们会自动获取gzip。 (请参阅我的上一个问题,了解我为什么感到困惑这个)

When I use my Rails app to directly serve my assets through Heroku's Cedar stack (ie. NOT through a CDN) they get gzip'd automatically. (See my previous question on why I'm confused about this)

现在,我试图设置Cloudfront来代替这些资产,理想情况下,我希望他们也是gzip的。从我所看到的,我认为Cloudfront会将接受标头传递给我的应用程序,所以如果支持,它们应该被gzip提供(就像它们一样)当您直接向英雄的资产请求时)。但事实并非如此。资产标头最终看起来像这样:

Now, I'm trying to set up Cloudfront to serve these assets instead, and ideally, I'd like for them to be gzip'd as well. From what I've read, I thought that Cloudfront would pass on the Accept headers to my app, so they should be served up gzip'd if supported (just as they are when you make a direct request to the asset on heroku). But this isn't the case. The asset headers end up looking like this:

Age:510
Connection:keep-alive
Content-Length:178045
Content-Type:text/css
Date:Sun, 08 Jan 2012 18:55:13 GMT
Last-Modified:Sun, 08 Jan 2012 18:42:34 GMT
Server:nginx/0.7.67
Via:1.1 varnish, 1.0 7a0b4b3db0cc0d369fe1d6981bfb646a.cloudfront.net:11180 (CloudFront), 1.0 6af08f4042ec142b4b760ca4cd62041d.cloudfront.net:11180 (CloudFront)
X-Amz-Cf-Id:2b205edf4e9ef000a31a0208ca68f4e15b746eb430cde2ba5cc4b7dff4ba41a76c24f43cf498be02,8d5863a42eea452f86831a02f3eb648b26fe07013b08b95950f15ef8ba275822e1eb3b7ed2550d01
X-Cache:Hit from cloudfront
X-Varnish:2130919357

这里没有提到编码,当我查看普通文件时,它不是gzip的。所以我想知道我需要做什么来让Cloudfront从我的应用程序请求一个gzip的资产版本,以便它可以将它提供给客户端。

There's no mention of encoding here, and when I view the plain file, it's not gzip'd. So I'm wondering what I need to do here to get Cloudfront to request a gzip'd version of the asset from my app so that it can serve this to the client.

此帖表示您需要手动gzip并上传该文件,但我不明白为什么这是必要的。一个,这是烦人的,两个,它不会要求文件与我的浏览器直接相同?那么为什么它不会在我的应用程序中默认提供gzip文件?

This post says you need to manually gzip and upload the file, but I don't see why that should be necessary. For one, it's annoying, and two, wouldn't it request the file the same as my browser directly? So why wouldn't it just serve up the gzip'd file as it does by default in my app?

任何获取gzip工作正常的提示将是很棒的。我想不需要手动gzip我的文件,如果可能的话上传它们。

Any tips on getting gzip'ng working properly would be great. I'd like to not have to manually gzip my files and upload them if possible.

推荐答案

Cedar服务的文件不要被GZipped通过堆栈,雪松只服务于应用程序代码中的任何内容。请参阅文档

Cedar served files do NOT get GZipped by the stack, Cedar only serves whatever you have in the application code. See the documentation:


由于向Cedar应用程序的请求直接发送到应用程序
服务器 - 不通过像nginx这样的HTTP服务器代理 - 任何
压缩的响应必须在您的应用程序中完成。对于
Rack应用程序,这可以通过Rack :: Deflater
中间件来实现。对于gzip压缩的静态资产,请确保在中间件堆栈中的ActionDispatch :: Static之前加载了Rack :: Deflater

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. For Rack apps, this can be accomplished with the Rack::Deflater middleware. For gzipped static assets, make sure that Rack::Deflater is loaded before ActionDispatch::Static in your middleware stack.



Therefore the GZipping your seeing either is a false header, or is coming from somewhere else which. Therefore if you've just pushed files to Cloudfront then you're just seeing the same thing.

如果您正在通过CDN提供压缩资产,我真的会推荐看到碰撞到Rails 3.1并使用资产管道。这不仅会给你更多的控制你的资产bu也给你一个更容易的路径

If you're looking at serving zipped assets via CDN I would really recommend looking at bumping to Rails 3.1 and using the Asset pipeline. Not only will this give you more control over your assets bu also give you a much easier path to serving them over a CDN.

这篇关于接收 - 编码Cloudfront上的标题,从Heroku Cedar的Rails 3.0.x上提供资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆