首页 文章

IIS反向代理到Node.js - 静态压缩

提问于
浏览
0
  • Windows Server 2012

  • IIS 8.5

我们已将IIS设置为Node.js Web服务器的反向代理(两者都在同一个盒子上运行) . 我无法通过IIS将静态压缩工作用于从Node.js提供的资源 .

  • 要重写请求URL,我们使用URL Rewrite模块和入站规则 . 没有出站规则 .

  • 在Node.js中禁用了压缩 - 我们希望IIS对Node.js的响应进行压缩

  • We have tested Dynamic Compression (using default GZip compression) and everything is working fine.

  • Static Compression is working but only for files local to the IIS site (i.e. not served from Node.js), when the Inbound rule is disabled.

  • page表示“Oubound重写不能与IIS静态压缩一起使用 . ”但是,我们没有任何出站规则 .

  • 我启用了失败的请求跟踪,但在启用入站规则时无法在跟踪中看到任何STATIC_COMPRESSION_START条目 .

  • 在IIS Web服务器配置中,我尝试了各种设置,例如staticCompressionIgnoreHitFrequency = "true",请参阅下面的示例 .

问:当反向代理Node.js时,我们如何启用静态压缩?

服务器配置中的示例:

<httpCompression directory="C:\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="1" noCompressionForHttp10="false" noCompressionForProxies="false" noCompressionForRange="false" staticCompressionIgnoreHitFrequency="true" staticCompressionEnableCpuUsage="1" >
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="application/atom+xml" enabled="true" />
            <add mimeType="application/xaml+xml" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </staticTypes>
        <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
    </httpCompression>

来自站点web.config的示例:

<configuration>
  <system.webServer>
<rewrite>
      <rules>
        <clear></clear>
        <rule name="ReverseProxyInboundRule1" enabled="false" stopProcessing="true">
          <match url="(.*)" />
          <action type="Rewrite" url="http://localhost:3000/{R:1}" />
        </rule>
      </rules>
    </rewrite>

    <urlCompression doStaticCompression="true" doDynamicCompression="false" />


  </system.webServer>
</configuration>

1 回答

  • 0

    我尝试使用IIS作为另一个IIS站点(而不是Node)的反向代理,并在此处粘贴相关问题:https://serverfault.com/questions/909149/iis-rewrite-module-and-static-compression

    这导致上面的Node问题的解决方案 . 你需要:

    1)忘记静态压缩模块(在反向代理使用ARR时禁用),而是启用ARR缓存(启用压缩) . 这将是Gzip的ARR缓存内容 . However ....

    2)我注意到这对JS文件不起作用 . 原因是我们的Node服务器将JS文件的Content-Type设置为“application / javascript; charset = UTF-8” . 默认情况下,ARR配置为查找不带字符编码的内容类型 .

    要解决此问题,请在\ Windows \ System32 \ inetsrv \ config \ applicationHost.config中添加 <add mimeType="application/javascript; charset=UTF-8" enabled="true" /> 映射,具体如下:

    <diskCache>
            <driveLocation path="C:\inetpub\arrCache" maxUsage="5" />
            <compression>
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/x-javascript" enabled="true" />
                <add mimeType="application/javascript" enabled="true" />
                <add mimeType="application/javascript; charset=UTF-8" enabled="true" />
            </compression>
        </diskCache>
    

相关问题