IIS应用程序缺少Content-Encoding - 响应标头中的gzip [英] IIS application missing Content-Encoding - gzip in Response Header

查看:385
本文介绍了IIS应用程序缺少Content-Encoding - 响应标头中的gzip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firebug中,请求标头包含以下条目:

接受编码:gzip,deflate

In Firebug the request header has the following entry:
Accept-Encoding: gzip, deflate

但是没有:

内容编码:gzip

在响应标题中。

But there's no:
Content-Encoding: gzip
In the Response Header.

无论我尝试过什么,在SO和其他网站上的一些答案后,似乎没有任何作用!静态文件或动态文件都没有被压缩,或者至少如果它们没有内容编码 - gzip值在响应头中返回。

Regardless of anything I've tried, following a number of answers on SO and other sites, nothing seems to work! Neither static nor dynamic files are being compressed, or at least if they are there's no content encoding - gzip value coming back in the response header.

以下是我的web.config设置示例:

Here's an example of my web.config settings:

<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="150" staticCompressionIgnoreHitFrequency="true">
  <remove name="gzip" />
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="8" dynamicCompressionLevel="8" />
</httpCompression>

我忽略了命中频率

staticCompressionIgnoreHitFrequency =true

我已经确认IIS实际上压缩了我可以看到的文件:

C:\inetpub\temp\IIS临时压缩文件

I've confirmed that IIS is in fact compressing the files which I can see in:
C:\inetpub\temp\IIS Temporary Compressed Files

此处指定:在IIS 8 windows 8中设置gzip

我确保静态Windows功能> Internet信息服务> WWW服务>性能功能中启用了动态压缩

As specified here: set up gzip in IIS 8 windows 8
I've ensured that static and dynamic compression is enabled in Windows Features > Internet Information Services > WWW Services > Performance Features

我也试过这个人的方法:

< a href =https://stackoverflow.com/questions/28833861/iis-7-5-compression-creates-compressed-file-but-returns-the-non-compressed-one> IIS 7.5压缩创建压缩文件但是返回未压缩的

I've also tried this guy's approach:
IIS 7.5 Compression creates compressed file but returns the non-compressed one

编辑1:

IIS版本sion是10,但我也在IIS 8.5上试过这个

Edit 1:
IIS version is 10 but I have also tried this on IIS 8.5

编辑2:

我现在也尝试了在这个链接上找到的各种配置文件:
https://github.com/h5bp/server-configs-iis/ 提供了一些最佳实践web.config文件。

未解决

Edit 2:
I've now also tried various configuration files found at this link: https://github.com/h5bp/server-configs-iis/ which provides what looks like some 'best practice' web.config files.
Not solved

编辑3:

基于@Nkosi的输入我创建了一个全新的Asp.net MVC应用程序,并使用我尝试过的所有这些选项对其进行配置。
这是我从Fiddler得到的原始标题:

Edit 3:
Based on @Nkosi's input I created a completely new Asp.net MVC application and configured it using all these options I've tried. Here's the raw header that I got from Fiddler:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: text/javascript; charset=UTF-8
Expires: Wed, 20 Jul 2016 18:22:47 GMT
Last-Modified: Wed, 20 Jul 2016 18:22:47 GMT
Server: Microsoft-HTTPAPI/2.0
Date: Wed, 20 Jul 2016 18:22:47 GMT

当你可以看到,没有Content-Encoding:Gzip

未解决

As you can see, no Content-Encoding: Gzip
Not solved

编辑4:

我尝试过这种方法将代码添加到Global.asax部分的BeginRequest事件中:https://stackoverflow.com/a/27185575/392591

未解决

编辑5:

所以我只是尝试根据这个答案在SO上启用跟踪: https://stackoverflow.com/a/33182525/392591

没有失败,但我确实注意到了跟踪文件的底部有一个名为GENERAL_RESPONSE_HEADERS的部分,这里是它提供的内容:

Edit 5:
So I just tried enabling tracing based on this answer on SO: https://stackoverflow.com/a/33182525/392591
No failures, but I did notice right at the bottom of the trace file there's a section called GENERAL_RESPONSE_HEADERS and here's what it provides:

Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-Powered-By: My Little Pony
X-UA-Compatible: IE=Edge,chrome=1

这适用于每个静态类型文件。

但是我刚在跟踪文件中找到以下内容:

And that's for every static type file.
However I just found the following in the trace file:

8. STATIC_COMPRESSION_START  08:04:03.552 
9. STATIC_COMPRESSION_NOT_SUCCESS Reason="NOT_FREQUENTLY_HIT" 08:04:03.552 
10. STATIC_COMPRESSION_END  08:04:03.552 

压缩不成功因为不经常点击...奇怪,因为我肯定将Ignore Hit Frequency选项设置为true!

Compression Not Success for the reason Not Frequently Hit... Odd because I definitely have the Ignore Hit Frequency option set to true!

所以我刚进入IIS管理器并在服务器上将Ignore Hit Frequency设置为true(即applicationHost.config)并将跟踪文件输出更改为以下内容:

So I just went into IIS Manager and on the server I set the Ignore Hit Frequency to true (i.e. applicationHost.config) and it changed the trace file output to the following:

8. STATIC_COMPRESSION_START  08:19:17.489 
9. STATIC_COMPRESSION_SUCCESS  08:19:17.489 
10. STATIC_COMPRESSION_END  08:19:17.489 

我回去并在applicationHost.config中将其关闭,然后又回到静态压缩不成功,所以这肯定有所作为。但是,当我查看FireBug时,它仍然传递未压缩文件而没有GZIP内容编码响应头。

I went back and switched it off in the applicationHost.config and it went back to a Static Compression Not Success, so this definitely makes a difference. However, when I look at FireBug, it's still delivery the uncompressed file and no GZIP Content Encoding response header.

我在失败的请求跟踪中注意到的另一个有趣的位是最后两个entires GENERAL_FLUSH_RESPONSE_END和GENERAL_REQUEST_END两个都显示我的Bootstrap.css文件发送了17903个字节,大约18kb ,匹配我在IIS Temporary Compressed Files文件夹中看到的文件的压缩版本。所以该文件在物理上被压缩,根据失败的请求跟踪它发送正确的内容...但是然后浏览器选择了完整的117kb文件?

未解决

Another interesting bit I noticed in the Failed Request Trace is the final two entires GENERAL_FLUSH_RESPONSE_END and GENERAL_REQUEST_END both of which show my Bootstrap.css file as having sent 17903 bytes, roughly 18kb, matching the compressed version of the file I see in my IIS Temporary Compressed Files folder. So the file is physically being compressed and according to Failed Request traces it's sending down the right content... but then the browser picks up the full 117kb file instead?
Not solved

推荐答案

我正在使用IIS10而我的web.config已经

I am using IIS10 and my web.config has

<system.webServer>
    <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false" />
    <!-- other config removed for brevity -->
</system.webServer>

当我测试来自浏览器(Firefox,IE11,Edge,Google Chrome)的请求时MVC应用程序。

When I do test requests from a browser (Firefox, IE11, Edge, Google Chrome) to a simple MVC application.

请求全部接受编码:gzip,deflate ,响应返回内容-Encoding:gzip

我甚至用Fiddler测试过它。手动编写请求

I Even tested it with Fiddler. Composing the request manually

GET http://localhost/MyWebApplication HTTP/1.1
User-Agent: Fiddler
Host: localhost
Accept-Encoding: gzip, deflate

并获得相同的结果

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 18 Jul 2016 15:26:06 GMT
Content-Length: 3826

...

正在压缩Css,Js和所有其他基于文本的文件。

Css, Js and all other text based files are being compressed.

您可能需要重新检查配置,以确保在IIS和web.config中正确配置压缩。

You may need to re-check your configuration to make sure you have the compression properly configured in IIS and your web.config.

更新:

我注意到图片没有被压缩

I did notice that images were not being compressed

请求

GET http://localhost/MyWebApplication/Images/Logo_small.png HTTP/1.1
User-Agent: Fiddler
Host: localhost
Accept-Encoding: gzip, deflate

响应

HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: image/png
Last-Modified: Fri, 27 Nov 2015 03:15:22 GMT
Accept-Ranges: bytes
ETag: "c9d1fdd9c128d11:0"
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Mon, 18 Jul 2016 15:33:02 GMT
Content-Length: 2970

...

在一些google-fu之后发现图像通常已被压缩,因此未应用gzip。

And after some google-fu found out that the images are usually already compressed so gzip was not applied.

来自web.config的完整system.webServer

  <system.webServer>
    <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="false" />
   <validation validateIntegratedModeConfiguration="false" />
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <clear />
      <error statusCode="404" responseMode="ExecuteURL" path="/NotFound" />
    </httpErrors>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <staticContent>
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </staticContent>
  </system.webServer>

这篇关于IIS应用程序缺少Content-Encoding - 响应标头中的gzip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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