IIS 7.5 成功壓縮但發送未壓縮版本作為回應

IIS 7.5 成功壓縮但發送未壓縮版本作為回應

我將 IIS 7.5 設定為對靜態和動態內容使用 gzip 壓縮。透過檢查“IIS 臨時壓縮檔案”資料夾,我已經驗證它確實壓縮了我在配置中定義的所有靜態 MIME 類型。我還強制執行失敗請求跟踪,發現當請求傳入(靜態和動態)時,壓縮正在成功執行,沒有錯誤。

但是,IIS 發送回瀏覽器的回應是未壓縮的。回應的大小相同,且回應中沒有「Content-Encoded:gzip」標頭。

我的 IIS 配置:

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="1" noCompressionForHttp10="false" noCompressionForProxies="false">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/json" enabled="true" />
            <add mimeType="application/json; charset=utf-8" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="application/x-javascript; charset=utf-8" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/atom+xml" enabled="true" />
            <add mimeType="application/xaml+xml" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="application/x-javascript; charset=utf-8" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </staticTypes>
    </httpCompression>
    ...
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    ...
    <serverRuntime frequentHitThreshold="1" />

範例請求(範例是動態的,但也同樣處理靜態類型):

    Accept:application/json, text/plain, */*
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8
    Cache-Control:no-cache
    Connection:keep-alive
    Content-Length:0
    Cookie:ASP.NET_SessionId=...
    Host:...
    Origin:...
    Pragma:no-cache
    Referer:...
    User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36

回應範例:

    Cache-Control:private
    Content-Type:application/json; charset=utf-8
    Date:Tue, 29 Sep 2015 21:37:28 GMT
    Server:Microsoft-IIS/7.5
    Set-Cookie:.ASPXAUTH=...
    Transfer-Encoding:chunked
    Vary:Accept-Encoding
    X-AspNet-Version:4.0.30319
    X-AspNetMvc-Version:5.0
    X-Powered-By:ASP.NET

再次,我已經驗證它壓縮成功,只是由於某種原因沒有在回應中發送壓縮資料。

相關內容