以S3网站为来源的CloudFront不提供压缩文件 [英] CloudFront with S3 website as origin is not serving gzipped files

查看:133
本文介绍了以S3网站为来源的CloudFront不提供压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AWS现在支持通过CloudFront对文件进行gzip压缩

我已经按照提供压缩文件,但gzip压缩不起作用。

I've followed along with all of the instructions in Serving Compressed Files, and yet gzipping is not working.

我已经设置了一个S3存储桶作为将CloudFront用作来源的网站。

I have an S3 bucket set up as a website that CloudFront is using as the origin.


  • 自动压缩对象是已启用

  • 我正在提供具有正确内容类型的文件,例如 application / javascript text / css

  • 文件在1,000和10,000,000字节之内

  • S3网站为文件提供据我所知,Content-Length

  • 为了确保没有缓存,我使整个S3存储桶和uplo都无效将文件的新版本添加到S3。

  • 此外,我使用的Web浏览器Chrome确实接受压缩文件。

  • Compress Objects Automatically is enabled
  • I am serving files with the correct content types such as application/javascript and text/css
  • The files are within 1,000 and 10,000,000 bytes
  • The S3 website serves the files with a Content-Length as far as I know
  • To be extra sure nothing was cached, I both invalidated the entire S3 bucket and uploaded newer versions of the files to S3.
  • Additionally, the web browser I am using, Chrome, does accept gzipped files.

尽管如此,我还是无法gzipping工作。我已经获得了包括SSL在内的所有其他功能,您可以在此处访问该网站: https://formulagrid.com/

Despite all this, I can't get gzipping to work. I have gotten everything else including SSL working perfectly, and you can visit the site here: https://formulagrid.com/

如果打开chrome控制台,您会注意到从S3提供的所有文件均未压缩。我从其他CDN抓取的文件中只有gzip压缩文件,例如google字体。

If you open up the chrome console, you'll notice that none of the files being served from S3 are being gzipped. The only gzipped files such as the google font are the ones I'm grabbing from other CDNs.

推荐答案

我遇到了相同的错误今天,通过在S3存储桶中添加CORS规则解决了该问题。此规则确保将Content-Length标头发送到Cloudfront,以便可以将内容压缩:

I hit the same error today and solved it by adding a CORS rule to the S3 bucket. This rule ensures the Content-Length header is sent to Cloudfront so content can be gzipped:

S3>存储桶>权限> CORS配置

S3 > Bucket > Permissions > CORS Configuration

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
        <AllowedHeader>Content-Length</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

信用归Robert Ellison所有: http://ithoughthecamewithyou.com/post/enable-gzip-compression-for-amazon-s3-hosted-云端站点

Credit goes to Robert Ellison: http://ithoughthecamewithyou.com/post/enable-gzip-compression-for-amazon-s3-hosted-website-in-cloudfront

据我所知,这似乎是没有记录的要求。

As far I know, this seems to be an undocumented requirement.

这篇关于以S3网站为来源的CloudFront不提供压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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