亚马逊EC2走秀gzip压缩的JavaScript。但是的Cloudfront没有。为什么? [英] Amazon EC2 serves gzipped JavaScript. But Cloudfront does not. Why?

查看:174
本文介绍了亚马逊EC2走秀gzip压缩的JavaScript。但是的Cloudfront没有。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有供应,当接受编码头设置为 GZIP 。但是,当我提出同样的要求与原始服务器作为我的Amazon EC2实例完全相同的头一个CloudFront的CDN,它并没有发回一个gzip压缩的响应。

I have an Amazon EC2 Web Server instance which serves gzipped content when the Accept-Encoding header is set to gzip. But when I make the same request with the exact same header to a CloudFront CDN with the origin server as my Amazon EC2 instance, it doesn't send back a gzipped response.

我也尝试创建一个新的CloudFront的分布(因为我认为,旧的发行版可能会uncom pressed响应缓存),然后作出同样的要求,我仍然得到一个uncom pressed响应。

I also tried creating a new CloudFront distribution(because I thought that the old distribution might have uncompressed response cached) and then making the same request and I still get an uncompressed response.

有人能告诉我什么,我可能会丢失?

Can someone please tell me what I may be missing?

推荐答案

这已被标记为与S3的问题可能重复。现在的问题是围绕EC2 - 不是S3,所以我不认为这是一个重复

This has been marked as a possible duplicate of a question relating to S3. The question is around EC2 - not S3, so I don't think this is a duplicate.

您很可能会看到这个问题的原因的Cloudfront添加通过头向你的原始服务器提出的要求 - 这是一个已知问题与IIS

You’re likely seeing this issue due to Cloudfront adding a ‘Via’ header to the requests made to your origin server - it’s a know issue with IIS.

如果你看看传入的HTTP请求到你的出身,你会看到你的HTTP头是这样的:

If you were to look at the incoming HTTP requests to your origin, you’d see something like this in your HTTP headers:

Via=1.1 9dc1db658f6cee1429b5ff20764c5b07.cloudfront.net (CloudFront)
X-Amz-Cf-Id=k7rFUA2mss4oJDdT7rA0HyjG_XV__XwBV14juZ8ZAQCrbfOrye438A==
X-Forwarded-For=121.125.239.19, 116.127.54.19

增加了一个通过报头是标准的代理服务器的行为。当IIS看到这个,它丢弃了gzip的加密(我猜是由于一个假设,即旧的代理服务器无法处理COM pressed内容)。

The addition of a ‘Via’ header is standard proxy server behaviour. When IIS sees this, it drops the gzip encryption (I’m guessing due to an assumption that older proxy servers couldn’t handle compressed content).

如果您做出以下更改的applicationHost.config,你应该纠正这个问题:

If you make the following changes to your applicationHost.config, you should rectify the issue:

<location path="Your Site">
  <system.webServer>
    <httpCompression noCompressionForHttp10="false" noCompressionForProxies="false" />
  </system.webServer>
</location>

另一个问题需要注意的是,IIS不总是COM preSS收到给定资源的第一反应,因此,的Cloudfront可以提出请求的来源,接收,缓存,然后服务于uncom pressed版的内容,随后游客。同样,你可以使用的的applicationHost.config的serverRuntime中的设置修改此行为:

The other issue to watch out for is that IIS doesn’t always compress the first response it receives for a given resource, therefore, Cloudfront may make a request to the origin, receive, cache and then serve uncompressed version of the content to subsequent visitors. Again you can modify this behaviour using the serverRuntime settings in the applicationHost.config:

<location path="Your Site">
  <system.webServer>
    <httpCompression noCompressionForHttp10="false" noCompressionForProxies="false" />
    <serverRuntime frequentHitThreshold="1" frequentHitTimePeriod="00:00:05"       />
  </system.webServer>

在这里这些设置的详细信息: http://www.iis.net/configreference/system.webserver/serverruntime http://www.iis.net/configreference/system.webserver/httpcom pression

More details on these settings here: http://www.iis.net/configreference/system.webserver/serverruntime http://www.iis.net/configreference/system.webserver/httpcompression

感谢这篇博客文章解释了这个问题: <一href="http://$c$cpolice.net/2012/06/26/problems-with-gzip-when-using-iis-7-5-as-an-origin-server-for-a-cdn/" rel="nofollow">http://$c$cpolice.net/2012/06/26/problems-with-gzip-when-using-iis-7-5-as-an-origin-server-for-a-cdn/

Credit to this blog post for explaining the issue: http://codepolice.net/2012/06/26/problems-with-gzip-when-using-iis-7-5-as-an-origin-server-for-a-cdn/

这篇关于亚马逊EC2走秀gzip压缩的JavaScript。但是的Cloudfront没有。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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