We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

View Complete Thread
  • IIS Reverse Proxy for Nextcloud - preserve HTTP_HOST

    May 05, 2019 02:28 PM|RockNLol|LINK


    I'm trying to reverse proxy cloud.mydomain.com to a debian nextcloud vm internally reachable under cloud.mydomain.local. The website itself works fine, after telling nextcloud not to use gzip for compression, but I can't use nextclouds sync client. After entering the external url, the sync client tries to connect to the internally used URL which is configured in url rewrite. I guess this is because it is transferred by HTTP_HOST.

    Can I somehow make nextcloud think the connection came from a different URL?

    This is my web.config so far: (I tried to overwrite HTTP_HOST and SERVER_NAME with the desired external url, but it does not work. I'm now testing with little php file just echoing HTTP_HOST and SERVER_NAME)

    <?xml version="1.0" encoding="UTF-8"?>
    <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
    <match filterByTags="A, Form, Img" pattern="^http(s)?://cloud.mydomain.local/(.*)" />
    <action type="Rewrite" value="http{R:1}://cloud.mydomain.com/{R:2}" />
    <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
    <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
    <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
    <rule name="RestoreHttpHost" preCondition="NeedsRestoringOriginalHost">
    <match serverVariable="HTTP_HOST" pattern="^(.*)" />
    <action type="Rewrite" value="{HTTP_X_ORIGINAL_HOST}" />
    <preCondition name="ResponseIsHtml1">
    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    <preCondition name="NeedsRestoringAcceptEncoding">
    <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
    <preCondition name="NeedsRestoringOriginalHost">
    <add input="{HTTP_X_ORIGINAL_HOST}" pattern=".+" />
    <rule name="ReverseProxyInboundRule1" stopProcessing="true">
    <match url="(.*)" />
    <action type="Rewrite" url="http://cloud.mydomain.local/{R:1}" />
    <set name="HTTP_ACCEPT_ENCODING" value="" />
    <set name="HTTP_HOST" value="cloud.mydomain.com" />
    <set name="SERVER_NAME" value="cloud.mydomain.com" />
    <httpErrors errorMode="Detailed" />
    <remove name="X-Powered-By" />

    Thanks in advance,