Gzip not working, server 2012, IIS 8

2020-03-30 06:17发布

问题:

Problems with activating Gzip on IIS 8 on a windows server 2012 (standard)

  • So i activated the compressions in the windows features
  • I checked both checkboxes in IIS - compression (dynamic and static)

But still no Gzip available. However, on my localhost machine (just a windows 10) this works.

What i do see, is that the gzip temp directory (C:\inetpub\temp\IIS Temporary Compressed Files) is getting filled up when i browse my site via the server localhost. BUT strangely enough i'm not seeing anything Gzip-ped in chrome.

The only headers (in chrome) are: HTTP/1.1 304 Not Modified Accept-Ranges: bytes ETag: "0a354779de8d11:0" Server: Microsoft-IIS/8.0 X-Powered-By: ASP.NET Date: Thu, 28 Jul 2016 13:41:04 GMT

(Even yslow is saying no gzip is activated)

When i remove the gzip temp folder, and browse to the site trough the 'official' website url, then nothing is even generated.

Does anyone has any idea what is going on here?

//edit: Even added this in the web.config

<httpCompression> 
  <staticTypes> 
    <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="image/jpeg" enabled="true" /> 
    <add mimeType="*/*" enabled="false" /> 
  </staticTypes> 
  <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="image/jpeg" enabled="true" /> 
    <add mimeType="*/*" enabled="false" /> 
  </dynamicTypes> 
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4" /> 
</httpCompression>

回答1:

Here's how I would troubleshoot this:

I'm using PowerShell here, but you could use the GUI or other tools as well:

Make sure you have the failed request tracing module installed:

Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing

enable the tracing for your site (change the name):

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='Default Web Site']/traceFailedRequestsLogging" -name "enabled" -value "True"

Setup tracing:

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/tracing/traceFailedRequests" -name "." -value @{path='*.html'}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/tracing/traceFailedRequests/add[@path='*.html']/traceAreas" -name "." -value @{provider='WWW Server';areas='Compression';verbosity='Verbose'}
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/tracing/traceFailedRequests/add[@path='*.html']/failureDefinitions" -name "statusCodes" -value "200,304"

you end up with something like this in your web.config:

<system.webServer>
    <tracing>
        <traceFailedRequests>
            <add path="*.html">
                <traceAreas>
                    <add provider="WWW Server" areas="Compression" verbosity="Verbose" />
                </traceAreas>
                <failureDefinitions statusCodes="200,304" />
            </add>
        </traceFailedRequests>
    </tracing>
</system.webServer>

I limited it to html files with a http status of 200 or 304 and we are only interested in Compression. You may want to change that.

Now you can hit your site a few times and then look in

C:\inetpub\logs\FailedReqLogFiles\W3SVCx

for some files, copy them to your workstation, because it's a pain to open them on the server.

Open the XML files and click on the Request Details tab, now search for Compression you should see details about the compression process or a reason why the request wasn't compress, like NOT_FREQUENTLY_HIT or TOO SMALL