IIS10中minFileSizeForComp对动态压缩不生效问题求助
解决IIS10动态压缩最小响应大小设置问题
要实现动态压缩的最小响应大小控制,你需要通过修改IIS核心配置或命令行配置来完成——默认的minFileSizeForComp属性仅作用于静态压缩,动态压缩需单独配置。以下是具体可行方案:
方案1:编辑applicationHost.config配置文件
- 以管理员权限打开IIS核心配置文件,路径通常为
C:\Windows\System32\inetsrv\config\applicationHost.config - 找到
<httpCompression>节点,默认结构示例:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <staticTypes> <add mimeType="text/*" enabled="true" /> <!-- 其他静态类型配置 --> </staticTypes> <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/javascript" enabled="true" /> <!-- 其他动态类型配置 --> </dynamicTypes> </httpCompression>
- 若要仅针对动态压缩设置最小响应大小,在
<dynamicTypes>的每个<add>节点中添加minFileSizeForComp="860"属性;若要让该值同时作用于静态和动态压缩,直接在<httpCompression>节点上添加该属性。示例:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <staticTypes> <!-- 原有静态类型配置 --> </staticTypes> <dynamicTypes> <add mimeType="text/*" enabled="true" minFileSizeForComp="860" /> <add mimeType="message/*" enabled="true" minFileSizeForComp="860" /> <add mimeType="application/javascript" enabled="true" minFileSizeForComp="860" /> <!-- 其他动态类型配置 --> </dynamicTypes> </httpCompression>
- 保存文件后,执行命令
iisreset重启IIS服务生效。
方案2:使用AppCmd命令行配置
若偏好命令行操作,可通过appcmd工具完成配置:
- 为指定动态MIME类型设置最小压缩大小:
appcmd set config -section:system.webServer/httpCompression /dynamicTypes.[mimeType='text/*'].minFileSizeForComp:"860" /commit:apphost appcmd set config -section:system.webServer/httpCompression /dynamicTypes.[mimeType='message/*'].minFileSizeForComp:"860" /commit:apphost appcmd set config -section:system.webServer/httpCompression /dynamicTypes.[mimeType='application/javascript'].minFileSizeForComp:"860" /commit:apphost
- 全局设置(同时影响静态和动态压缩):
appcmd set config -section:system.webServer/httpCompression /minFileSizeForComp:"860" /commit:apphost
执行命令后重启IIS服务即可。
方案3:URL Rewrite模块控制(可选)
若上述方法不生效,可通过URL Rewrite模块添加规则,当响应大小小于860字节时禁用压缩:
- 确保已安装IIS URL Rewrite模块
- 在服务器/站点级别打开URL Rewrite,添加空白规则:
- 匹配URL:
.*(匹配所有请求) - 条件:添加条件,输入
{RESPONSE_CONTENT_LENGTH},匹配类型选择小于,值填860 - 操作:选择
自定义响应,设置HTTP响应头为Content-Encoding,值留空,勾选替换现有值
- 匹配URL:
- 保存规则后重启站点生效。
内容的提问来源于stack exchange,提问作者Kaumudi Rawat
相关产品推荐
相关产品推荐

