0

I have a server (call the main server - run Window Server 2022 and use IIS 10 for the web server - private IP: 10.10.1.1) with the domain tuitentuan.com. I host some web on this server.

Today, I'm trying to create my cloud storage. I decided to use Nextcloud run on Ubuntu Server 22.04.2 (call it sub server - private IP: 10.10.1.10). It runs well on LAN.

Now, I want to public my NAT using my domain drive.tuitentuan.com, but I'm NAT my domain to the main server, so I can't NAT to my cloud storage. I'm tired to find some solution and found Reverse Proxy.

I'm trying following this guideline IIS with URL Rewrite as a reverse proxy, but it does not work for me.

Here is my web config for web drive.tuitentuan.com

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://10.10.1.10/{R:1}" />
                    <serverVariables>
                        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                    </serverVariables>
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://10.10.1.10/(.*)" />
                    <action type="Rewrite" value="http{R:1}://drive.tuitentuan.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="Rewrite uri a tag" preCondition="ResponseIsTextStar">
                    <match pattern="href=(.*?)https://10.10.1.10/(.*?)\s" />
                    <action type="Rewrite" value="href={R:1}https://drive.tuitentuan.com/{R:2}" />
                </rule>
                <rule name="Rewrite uri button tag" preCondition="ResponseIsTextStar">
                    <match pattern="action=(.*?)https://10.10.1.10/(.*?)\\" />
                    <action type="Rewrite" value="action={R:1}https://drive.tuitentuan.com/{R:2}\" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
                    </preCondition>
                    <preCondition name="NeedsRestoringAcceptEncoding">
                        <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                    </preCondition>
                    <preCondition name="ResponseIsTextStar">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

And here is my config in the hosts file (C:\Windows\System32\drivers\etc\hosts)

127.0.0.1   tuitentuan.com
127.0.0.1   tool.tuitentuan.com
127.0.0.1   cdn.tuitentuan.com
127.0.0.1   accounts.tuitentuan.com
127.0.0.1   drive.tuitentuan.com

With this config, I got an error redirected you too many times (you can try it to see the error at drive.tuitentuan.com).

All my server and service are running on default port (80, 443).

How do I resolve my problem?

Thank you for the time to read my post. Please ignore if there are errors in the article because of my limited understanding.

TuiTenTuan
  • 45
  • 7
  • So there is only redirected too many times error? Is there a detailed error message? About this error you can refer to this discussion: https://stackoverflow.com/questions/32523540/http-to-https-rewrite-too-many-redirect-loops-iis-7. You can use FRT: https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/using-failed-request-tracing-rules-to-troubleshoot-application-request-routing-arr to find out why the redirection failed. – TengFeiXie Jul 10 '23 at 09:58

0 Answers0