GZip压缩在IIS 7.5上无法正常工作

tug*_*erk 57 .net asp.net iis gzip iis-7.5

我试图支持IIS下的静态文件的GZip压缩(默认情况下应该启用但不能)但到目前为止还没有工作.这是<system.webServer>Web应用程序的web.config文件中节点下的部分;

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/json" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/atom+xml" enabled="true" />
    <add mimeType="application/xaml+xml" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </staticTypes>
</httpCompression>

<urlCompression doStaticCompression="true" />
Run Code Online (Sandbox Code Playgroud)

我尝试使用谷歌浏览器.这是请求标题;

接受:text/html,application/xhtml + xml,application/xml; q = 0.9,/ ; q = 0.8

接收字符集:ISO-8859-1,utf-8; Q = 0.7,*; Q = 0.3

接受编码:gzip,放气,SDCH

接受语言:EN-US,EN; Q = 0.8

缓存控制:无缓存

连接:保持活跃

主持人:我-网站网址

附注:无缓存

用户代理:Mozilla/5.0(Windows NT 6.0)AppleWebKit/534.30(KHTML,类似Gecko)Chrome/12.0.742.122 Safari/534.30

这些是响应标题;

接受-范围:字节

内容长度:232651

内容类型:应用程序/ x-的JavaScript

日期:2011年8月4日星期四08:58:19 GMT

ETag的: "a69135734a50cc1:0"

Last-Modified:Mon,01 Aug 2011 12:56:37 GMT

服务器:Microsoft-IIS/7.5

X-已启动方式:ASP.NET

我检查了applicationHost.config文件,发现了一些如下节点;

----

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />

----

<section name="urlCompression" overrideModeDefault="Allow" />

----

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>

----

<urlCompression />
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

Bra*_*000 42

经过大量的搜索,我终于找到了什么压缩工作在我的IIS 7.5上.首先,IIS不会压缩文件,除非它经常加载.这提出了一个问题"IIS经常考虑什么?" 嗯,默认值是每10秒2次.哎呀!

可以在web.config中更改此设置,但需要先在applicationHost.config中解锁该部分.以下是命令:

首先解锁部分:

C:\ Windows\System32\inetsrv\appcmd.exe解锁配置/section:system.webServer/serverRuntime

配置路径"MACHINE/WEBROOT/APPHOST"中的未锁定部分"system.webServer/serverRuntime".

完成后,编辑web.config文件并添加serverRuntime元素:

<?xml version ="1.0"encoding ="UTF-8"?>
  <configuration>
    <system.webServer>
      <serverRuntime frequentHitThreshold ="1"frequentHitTimePeriod ="10:00:00"/>
...

在这种情况下,我将其设置为在10小时内点击一次文件.您可以根据需要调整值.这是解释serverRuntime元素的文档:

http://www.iis.net/configreference/system.webserver/serverruntime

我希望这也有助于你的压缩工作.

注意:您还可以在applicationHost.config文件中设置serverRuntime元素,但我选择在web.config中更改它,因为我们有许多服务器和具有各种站点的服务器场,并且我更容易控制它从这个粒度级别.

  • 事实证明,您可以使用此参数完全避免"经常请求"的问题:httpCompression下的staticCompressionIgnoreHitFrequency.设为True. (9认同)

Eri*_*Law 29

要记住的一件事是,第一个命中通常会立即返回未压缩,但会旋转一个线程以在后台压缩文件,以便为将来的请求提供压缩服务.

此外,您是否尝试过使用其他客户端(例如IE)?

  • 从技术上讲,压缩仅发生于"频繁请求"的内容,其在system.webServer/serverRuntime中元素定义与[frequentHitThreshold和frequentHitTimePeriod属性(http://msdn.microsoft.com/en-us/library/ms692441. ASPX).查看更多[此处](http://www.ksingla.net/2006/06/changes_to_compression_in_iis7/). (6认同)
  • 哇,很高兴得到你的回答先生:)是的,尝试过不同的事情,但根本没有机会.尝试fiddler :)认为它可能是'%SystemDrive%\ inetpub\temp\IIS临时压缩文件'文件夹上的权限问题,但无法将其排序.我是否需要在iis上为我的网络应用程序的所有用户设置权限?因为我有近20个应用程序在运行,每个应用程序在服务器上都有自己的用户帐户."IIS Temporary Compressed Files"文件夹具有IIS_IUSRS用户的完全控制权限.缺少什么,我真的很想知道这里. (2认同)
  • 事实证明,您可以使用此参数完全避免"经常请求"的问题:httpCompression下的staticCompressionIgnoreHitFrequency.设为True. (2认同)

Chr*_*nko 13

确保在服务器上安装Dynamic Compression.在IIS下添加/删除功能.


Dal*_*son 6

我花了一些时间才弄明白这一点.在applicationHost.config文件中的system.webServer/serverRuntime节点上将frequentHitThreshold属性设置为1应该可以解决问题,如http://www.iis.net/ConfigReference/system.webServer/serverRuntime中所述.

您可以通过以管理员身份执行以下命令来执行此操作:

%windir%\system32\inetsrv\appcmd set config /section:serverRuntime /frequentHitThreshold:1 /commit:apphost
Run Code Online (Sandbox Code Playgroud)

一句警告 - "频繁命中"概念似乎并不特定于压缩.我不知道设置这个是否会产生其他后果!

  • 我认为您真正想要的设置是`&lt;httpCompression staticCompressionIgnoreHitFrequency =“ true” /&gt;` (2认同)