IIS Reverse Proxy for Nextcloud - preserve HTTP_HOST [Answered]RSS

4 replies

Last post May 13, 2019 03:08 PM by RockNLol

  • 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

  • Re: IIS Reverse Proxy for Nextcloud - preserve HTTP_HOST

    May 06, 2019 08:59 AM|Able|LINK

    Hi RockNLol

    According to your description, I still couldn't understand your requirement.Could you please post more details about what you want to do and what problem you meet?

    Else since it is a problem with Nextcloud ,I suggest that you could host this thread to Nextcloud forums.Here is the link, I hope it could help you.

    https://help.nextcloud.com/

    Best Regards

    Able

    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: IIS Reverse Proxy for Nextcloud - preserve HTTP_HOST

    May 06, 2019 10:53 AM|RockNLol|LINK

    Hi!
    I'll try to explain a little better:
    The nextcloud sync client, which is its own program, not a website, uses the public url of the nextcloud server to connect to it. To determine which url was used for the connection, it uses HTTP_HOST of the http header and saves it for future connections. Since nextcloud is only reverse proxied to via IIS it always gets the internally used url cloud.mydomain.local and not the originally used url cloud.mydomain.com, preventing connections from outside of the internal network.
    Yes, this is also a nextcloud issue, but none that is easy to fix on nextclouds side. Nevertheless I also asked a similar question on their forums, with no answer so far. For me it seems easier to fix this via IIS.

    Do you have an idea how I could send a different HTTP_HOST?
  • Re: IIS Reverse Proxy for Nextcloud - preserve HTTP_HOST

    May 07, 2019 07:29 AM|Able|LINK

    Hi RockNLol

    According to your description, we couldn't set the HTTP_HOST as server variable to change.If you want to set it and change it in rewrite rule,you will see as below:

    Best Regards

    Able

    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: IIS Reverse Proxy for Nextcloud - preserve HTTP_HOST

    May 13, 2019 03:08 PM|RockNLol|LINK

    hi! Just letting you know that I couldn't solve this issue in IIS and switched to haproxy on a debian Hyper-V VM which proxies all my websites now. This worked flawlessly after about an hour of work, including research.

    Thanks for trying anyways!