且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

配置IIS 7.5发送JSON响应gzip压缩,NO_MATCHING_CONTENT_TYPE

更新时间:2023-11-10 08:35:46

您想确保在 * / * MIME类型添加类型之后。另外,还要确保您已使用服务器管理器(或OptionalFeatures.exe)安装动态的COM pression模块

You want to make sure that the */* mime type is after the types you add. Also make sure that you have installed Dynamic Compression Module using Server Manager (or OptionalFeatures.exe)

这是我使用,以确保一个良好的COM pression完成的命令行。 (但要确保你确实已经安装了动态和静态的COM pression模块):

This is the command lines I use to make sure a good compression is done. (but make sure you actually have installed Dynamic and Static Compression modules):

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/serverRuntime /frequentHitThreshold:"1"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/urlCompression /doDynamicCompression:"True"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/json']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/json; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/x-javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/x-javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/x-javascript; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/x-javascript; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='*/*']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='*/*',enabled='False']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/x-javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/x-javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/x-javascript; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/x-javascript; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='*/*']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='*/*',enabled='False']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /noCompressionForHttp10:"False" /noCompressionForProxies:"False" /minFileSizeForComp:"2700"

运行此您%WINDIR后%\ SYSTEM32 \ INETSRV \设置\对ApplicationHost.config应该是这个样子(注意, / 的是在底部):

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="2700" 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>