I have a web server configuration where IIS serves as a proxy to forward requests to an internal application server. While the proxy functionality is operating correctly, I’m encountering challenges in ensuring that the responses are compressed before they return to the client.
My Setup:
- An internal web application hosted at
https://backend.local
which is not accessible to the public. - A public IIS server available at
https://public.example
that manages the main website and proxies requests to the internal application. - I aim to redirect requests from
https://public.example/service/PATH
tohttps://backend.local/PATH
.
I am using the URL Rewrite module alongside the ARR extension. Below is my current web.config
configuration:
<system.webServer>
<rewrite>
<rules>
<rule name="Forward to internal service" stopProcessing="true">
<match url="^service/(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://backend.local/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="FixAbsoluteLinks" preCondition="HtmlContent">
<match filterByTags="A, Form, Link, Script" pattern="^http(s)?://backend.local/(.*)" />
<action type="Rewrite" value="/service/{R:2}" />
</rule>
<rule name="FixRedirects" preCondition="HtmlContent">
<match serverVariable="RESPONSE_LOCATION" pattern="^http(s)?://backend.local/(.*)" />
<action type="Rewrite" value="/service/{R:2}" />
</rule>
<preConditions>
<preCondition name="HtmlContent">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression dynamicCompressionBeforeCache="false" />
</system.webServer>
The concern is that omitting the clearing of the HTTP_ACCEPT_ENCODING
header leads to an error: HTTP Error 500.52 - URL Rewrite Module Error. Outbound rewrite rules cannot be applied when the content of the HTTP response is encoded ("gzip").
On the contrary, when I do clear this header, there are no compression results observed when the content is sent back to the client. I’ve tried typical solutions such as setting dynamicCompressionBeforeCache="false"
and verifying the order of the modules.
Curiously, when I implement straightforward rewrite rules within the same application (like /old/PATH
to /new/PATH
), compression operates flawlessly. The challenge only arises when trying to rewrite responses to a different server.
Is there any possible way to ensure IIS compresses the final response after executing the outbound rewrite rules?