Odd reverse proxy behaviour #3307
-
I've setup reverse proxies before without much trouble, however with IPC is only working partially. <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" destination="" exactDestination="true" httpResponseStatus="Permanent" />
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule3" stopProcessing="true">
<match url="api/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
<set name="HTTP_X_FORWARDED_FOR" value="{REMOTE_ADDR}" />
</serverVariables>
<action type="Rewrite" url="ws://127.0.0.1:1242/api/{R:1}?password=abc123" />
</rule>
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="api/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
<set name="HTTP_X_FORWARDED_FOR" value="{REMOTE_ADDR}" />
</serverVariables>
<action type="Rewrite" url="http://127.0.0.1:1242/api/{R:1}?password=abc123" />
</rule>
<rule name="ReverseProxyInboundRule" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
<set name="HTTP_X_FORWARDED_FOR" value="{REMOTE_ADDR}" />
</serverVariables>
<action type="Rewrite" url="http://127.0.0.1:1242/{R:1}" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<rule name="ReverseProxyOutboundRule3" preCondition="ResponseIsHtml" patternSyntax="Wildcard" stopProcessing="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^ws://127.0.0.1:1242/api/(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="ws://my.domain.com/api/{R:1}" />
</rule>
<rule name="ReverseProxyOutboundRule2" preCondition="ResponseIsHtml" patternSyntax="Wildcard" stopProcessing="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^http://127.0.0.1:1242/api/(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="https://my.domain.com/api/{R:1}" />
</rule>
<rule name="ReverseProxyOutboundRule" preCondition="ResponseIsHtml" patternSyntax="Wildcard" stopProcessing="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^http://127.0.0.1:1242/(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="https://my.domain.com/{R:1}" />
</rule>
<preConditions>
<remove name="ResponseIsHtml" />
<preCondition name="ResponseIsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<remove name="NeedsRestoringAcceptEncoding" />
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Most likely your reverse proxy has problem forwarding There is an opion for you to use |
Beta Was this translation helpful? Give feedback.
-
Found a solution and it ended up being rather simple. IIS has a security feature regarding "double escaping", the quickest workaround is to open configuration editor and change to True the property system.webServer/security/requestFiltering@allowDoubleEscaping. If you want you can add my following example to the documentation. It already includes the allowDoubleEscape config. The only warning you need to give is that IIS users need to make sure the website has the server variables configured, otherwise the web.config in itself is useless. In my example are: HTTP_X_ORIGINAL_ACCEPT_ENCODING, HTTP_ACCEPT_ENCODING, HTTP_X_FORWARDED_FOR, RESPONSE_LOCATION. <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" destination="" exactDestination="true" httpResponseStatus="Permanent" />
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="api/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
<set name="HTTP_X_FORWARDED_FOR" value="{REMOTE_ADDR}" />
</serverVariables>
<action type="Rewrite" url="http://127.0.0.1:1242/api/{R:1}" />
</rule>
<rule name="ReverseProxyInboundRule" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
<set name="HTTP_X_FORWARDED_FOR" value="{REMOTE_ADDR}" />
</serverVariables>
<action type="Rewrite" url="http://127.0.0.1:1242/{R:1}" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<rule name="ReverseProxyOutboundRule2" preCondition="ResponseIsHtml" patternSyntax="Wildcard" stopProcessing="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^http://127.0.0.1:1242/api/(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="https://asf.mydomain.com/api/{R:1}" />
</rule>
<rule name="ReverseProxyOutboundRule" preCondition="ResponseIsHtml" patternSyntax="Wildcard" stopProcessing="true">
<match serverVariable="RESPONSE_LOCATION" pattern="^http://127.0.0.1:1242/(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true" />
<action type="Rewrite" value="https://asf.mydomain.com/{R:1}" />
</rule>
<preConditions>
<remove name="ResponseIsHtml" />
<preCondition name="ResponseIsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<remove name="NeedsRestoringAcceptEncoding" />
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</configuration> |
Beta Was this translation helpful? Give feedback.
Found a solution and it ended up being rather simple. IIS has a security feature regarding "double escaping", the quickest workaround is to open configuration editor and change to True the property system.webServer/security/requestFiltering@allowDoubleEscaping.
Ideally I think the matching pattern and server variables used could be improved but it works this way.
If you want you can add my following example to the documentation. It already includes the allowDoubleEscape config. The only warning you need to give is that IIS users need to make sure the website has the server variables configured, otherwise the web.config in itself is useless. In my example are: HTTP_X_ORIGINAL_ACCEPT_ENCODI…