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

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

    hi,

    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"?>
    <configuration>
    <system.webServer>
    <rewrite>
    <outboundRules>
    <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>
    <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
    <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
    <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
    </rule>
    <rule name="RestoreHttpHost" preCondition="NeedsRestoringOriginalHost">
    <match serverVariable="HTTP_HOST" pattern="^(.*)" />
    <action type="Rewrite" value="{HTTP_X_ORIGINAL_HOST}" />
    </rule>
    <preConditions>
    <preCondition name="ResponseIsHtml1">
    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    </preCondition>
    <preCondition name="NeedsRestoringAcceptEncoding">
    <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
    </preCondition>
    <preCondition name="NeedsRestoringOriginalHost">
    <add input="{HTTP_X_ORIGINAL_HOST}" pattern=".+" />
    </preCondition>
    </preConditions>
    </outboundRules>
    <rules>
    <rule name="ReverseProxyInboundRule1" stopProcessing="true">
    <match url="(.*)" />
    <action type="Rewrite" url="http://cloud.mydomain.local/{R:1}" />
    <serverVariables>
    <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
    <set name="HTTP_ACCEPT_ENCODING" value="" />
    <set name="HTTP_HOST" value="cloud.mydomain.com" />
    <set name="SERVER_NAME" value="cloud.mydomain.com" />
    </serverVariables>
    </rule>
    </rules>
    </rewrite>
    <httpErrors errorMode="Detailed" />
    <httpProtocol>
    <customHeaders>
    <remove name="X-Powered-By" />
    </customHeaders>
    </httpProtocol>
    </system.webServer>
    </configuration>

    Thanks in advance,

    R'N'L