简体   繁体   English

IIS 7动态内容压缩不起作用

[英]IIS 7 dynamic content compression not working

My IIS 7 dynamic content compression will not work as verified by server logs... bytes sent/received are identical with compression on and off. 我的IIS 7动态内容压缩无法通过服务器日志的验证。...发送/接收的字节与打开和关闭压缩相同。

Let me go through the things I've done so far to make sure this is done right: 让我仔细阅读到目前为止已经完成的事情,以确保正确完成:

1) Install dynamic compression module (duh) 1)安装动态压缩模块(DUH)
2) Enable dynamic compression 2)启用动态压缩
3) in web.config under system.webserver/httpCompression, I've added DynamicCompressionDisableCpuUsage=100 and DynamicCompressionEnableCpuUsage=99 to make sure that compression is on as often as possible. 3)在system.webserver / httpCompression下的web.config中,我添加了DynamicCompressionDisableCpuUsage = 100和DynamicCompressionEnableCpuUsage = 99以确保尽可能频繁地进行压缩。 server load is generally 0% to 2% CPU, so this shouldn't be a problem at all. 服务器负载通常为0%到2%CPU,因此这完全不是问题。
4) I changed system.webserver/httpCompression/scheme dynamicCompressionLevel from 0 to 7 since the default value is 0 4)我将system.webserver / httpCompression / scheme dynamicCompressionLevel从0更改为7,因为默认值为0
5) I've added the mime types and set enabled=true under system.webserver/httpCompression/dynamicTypes and ensured via a request analyzer that mimetype is indeed correct 5)我添加了mime类型并在system.webserver / httpCompression / dynamicTypes下设置了enabled = true,并通过请求分析器确保mimetype确实正确
6) After this, I've even restarted sites/recycled app pool. 6)之后,我什至重新启动了站点/回收的应用程序池。
7) I've even added mime-types to include the the charset, which I've read places sometimes affects dynamic compression. 7)我什至添加了mime-types来包含字符集,我读过的字符集有时会影响动态压缩。

I've still got no reduction in traffic! 我的流量仍然没有减少! What gives!? 是什么赋予了!? I even set system.webserver/httpCompression/minFileSizeForComp to 1000B even though that's only for static compression thinking that perhaps it might somehow carry over to dynamic compression. 我什至将system.webserver / httpCompression / minFileSizeForComp设置为1000B,尽管这仅用于静态压缩,但认为它可能会以某种方式延续到动态压缩中。 Bytes sent in the logs are still the same as without compression on. 日志中发送的字节数与未压缩时相同。

Here's my web.config section FYI: 这是我的web.config部分,仅供参考:

<system.webServer>
    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" dynamicCompressionDisableCpuUsage="100" dynamicCompressionEnableCpuUsage="99" minFileSizeForComp="1000">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="7" staticCompressionLevel="7"/>
        <dynamicTypes>
            <add mimeType="text/*" enabled="true"/>
            <add mimeType="message/*" enabled="true"/>
            <add mimeType="application/javascript" enabled="true"/>
            <add mimeType="application/x-javascript" enabled="true"/>
            <add mimeType="application/xml" enabled="true"/>
            <add mimeType="application/json" enabled="true"/>
            <add mimeType="application/json; charset=utf-8" enabled="true"/>
            <add mimeType="application/json; charset=UTF-8" enabled="true"/>
            <add mimeType="*/*" enabled="false"/>
        </dynamicTypes>
    </httpCompression>
    <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>

Here are a couple other questions I've referenced to come up with these settings... it seems like I've tried every trick in the book. 这是我参考来解决这些设置的其他几个问题……看来我已经尝试了本书中的所有技巧。

How can I get gzip compression in IIS7 working? 如何在IIS7中获得gzip压缩?
https://serverfault.com/questions/200041/how-do-determine-the-dynamiccompressiondisablecpuusage-setting-on-iis7 https://serverfault.com/questions/200041/how-do-determine-the-dynamiccompressiondisablecpuusage-setting-on-iis7

as per this ServerFault answer: https://serverfault.com/a/125156/117212 - you can't change httpCompression in web.config, it needs to be done in applicationHost.config file. 按照此ServerFault答案: https ://serverfault.com/a/125156/117212-您无法在web.config中更改httpCompression,它需要在applicationHost.config文件中完成。 Here is the code I use in my Azure web role to modify applicationHost.config file and add mime types for compression: 这是我在Azure Web角色中使用的代码来修改applicationHost.config文件并添加mime类型以进行压缩:

using (var serverManager = new ServerManager())
{
    var config = serverManager.GetApplicationHostConfiguration();
    var httpCompressionSection = config.GetSection("system.webServer/httpCompression");
    var dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes");

    Action<string> fnCheckAndAddIfMissing = mimeType =>
    {
        if (dynamicTypesCollection.Any(x =>
        {
            var v = x.GetAttributeValue("mimeType");
            if (v != null && v.ToString() == mimeType)
            {
                return true;
            }

            return false;
        }) == false)
        {
            ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add");
            addElement["mimeType"] = mimeType;
            addElement["enabled"] = true;
            dynamicTypesCollection.AddAt(0, addElement);
        }
    };

    fnCheckAndAddIfMissing("application/json");
    fnCheckAndAddIfMissing("application/json; charset=utf-8");

    serverManager.CommitChanges();
}

ServerManager comes from Microsoft.Web.Administration package in NuGet. ServerManager来自NuGet中的Microsoft.Web.Administration程序包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM