IIS/Nginx 的 HTTP/2、压缩与缓存
在 TLS 上启用 HTTP/2,正确压缩文本,设置缓存头,并避免双重压缩或缓存敏感页面。
测试环境Standard / Datacenter · 版本号 26100.33650 · x64
E1- 版本号
- 26100.33650
- 版本
- Standard / Datacenter
- 架构
- x64
- 支持
- 文档(E1)
- 证据
- E1官方文档
- 核验日期
- 2026-10-29
- 页面类型
- 任务
- HTTP/2 浏览器要求 TLS;现代 Windows 上 IIS 用 HTTPS 默认协商。
- 压缩只压文本(HTML/CSS/JS/JSON/SVG),别压图片/视频/zip。
- 缓存是按路径的策略;不要缓存认证后的 HTML。
HTTP/2
Section titled “HTTP/2”IIS:HTTPS 绑定是主要条件;HTTP/2 通过 ALPN 协商。Nginx:
listen 443 ssl;http2 on;验证:
curl.exe -I --http2 https://lab.example/状态行应显示 HTTP/2。还是 HTTP/1.1,检查 TLS/ALPN 和中间代理是否降级。
HTTP/2 不是 HTTP/3;QUIC 见 HTTP/3 页。
IIS web.config:
<system.webServer> <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" /> <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="application/json" enabled="true" /> <add mimeType="application/javascript" enabled="true" /> <add mimeType="*/*" enabled="false" /> </dynamicTypes> <staticTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="application/javascript" enabled="true" /> <add mimeType="image/svg+xml" enabled="true" /> <add mimeType="*/*" enabled="false" /> </staticTypes> </httpCompression></system.webServer>Nginx:
gzip on;gzip_types text/css application/javascript application/json image/svg+xml;gzip_min_length 1024;gzip_vary on;不要压已压缩文件;不要在代理和源站双重压缩。
<location path="assets"> <system.webServer> <staticContent> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" /> </staticContent> </system.webServer></location>带 hash 的资源可以长 max-age + immutable。HTML 用 no-cache 或短 TTL,部署才可见。
curl.exe -I --compressed https://lab.example/assets/app.jscurl.exe -I https://lab.example/account查 content-encoding、cache-control、vary,以及账户页不可公开缓存。
E1。实验室 IIS/Nginx 只跑 HTTP,没有验证 HTTP/2、压缩或 CDN 缓存。配置是 Server 2025 上待验证方案。