阅读背景:

以S3网站为原点的CloudFront不提供gzip压缩文件

来源:互联网 

AWS now supports gzipping files through CloudFront

AWS现在支持通过CloudFront gzipping文件

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

我已经按照服务压缩文件中的所有说明进行操作,但是gzipping不起作用。

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

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

  • Compress Objects Automatically is enabled
  • 自动压缩对象已启用
  • I am serving files with the correct content types such as application/javascript and text/css
  • 我正在使用正确的内容类型提供文件,例如application / javascript和text / css
  • The files are within 1,000 and 10,000,000 bytes
  • 这些文件在1,000和10,000,000字节之间
  • The S3 website serves the files with a Content-Length as far as I know
  • 据我所知,S3网站提供内容长度的文件
  • To be extra sure nothing was cached, I both invalidated the entire S3 bucket and uploaded newer versions of the files to S3.
  • 为了更加确定没有缓存任何内容,我都使整个S3存储桶失效并将更新版本的文件上传到S3。
  • Additionally, the web browser I am using, Chrome, does accept gzipped files.
  • 此外,我使用的网络浏览器Chrome也接受gzip压缩文件。

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/

尽管如此,我还是无法工作。我已经完成了包括SSL在内的所有其他工作,您可以访问以下网站:https://formulagrid.com/

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.

如果打开chrome控制台,您会注意到从S3提供的文件都没有被gzip压缩。唯一的gzip压缩文件,如谷歌字体是我从其他CDN抓取的。

1 个解决方案

#1


16  

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规则来解决它。此规则确保将Content-Length标头发送到Cloudfront,以便可以对内容进行gzip压缩:

S3 > Bucket > Permissions > CORS Configuration

S3> Bucket>权限> CORS配置

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="https://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>

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

感谢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.

据我所知,这似乎是一个无证的要求。


分享到: