Score:0

IIS and reverse proxy outbound rules

mn flag

I am trying to setup a reverse proxy using IIS 10 on Windows Server 2016 that must pass requests to an Apache Tomcat webapp.

It works for URLs within the 'basic' tags (such as a or img), but I need to configure outbound rules to process more than the tags that the IIS configuration offers (a, iframe, img, ...), such as :

  • <use xlink:href="..." >
  • <button onclick="..." >

Using custom tags does work to some extent, for instance within the use tag with href attribute, but not the xlink:href.

Here's the content that gets sent to the browser for a basic test file :

<!DOCTYPE html>
<html>
<head>
    <title>TEST</title>
    <link rel="stylesheet" type="text/css" href="https://external.mydomain.net/css/libs/bootstrap.min.css">
</head>

<body>
    <a href="https://external.mydomain.net/link">Some link</a>
    <button onclick="location.href='http://localhost:8080/link';" >Button</button>
    <div data-url="http://localhost:8080/link" />
    <svg>
        <use 
            href="https://external.mydomain.net/images/logos.svg#logo-g" 
            xlink:href="http://localhost:8080/images/logos.svg#logo-g">
        </use>
    </svg>
    http://localhost:8080/link
</body>

</html>

Some URLs get rewritten (like the a/href or svg/href), but some don't (like one button/onclick or svg/xlink:href)

Here is the IIS configuration file

<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Area, Base, Form, Head, IFrame, Img, Input, Link, Script, CustomTags" customTags="use" pattern="^http(s)?://localhost:8080(.*)" />
                    <action type="Rewrite" value="https://external.mydomain.net{R:2}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
                <customTags>
                    <tags name="use">
                        <tag name="use" attribute="xlink:href" />
                        <tag name="use" attribute="href" />
                        <tag name="input" attribute="value" />
                        <tag name="button" attribute="onclick" />
                        <tag name="div" attribute="data-url" />
                    </tags>
                </customTags>
            </outboundRules>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:8080/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

The problem is that, obviously, I need to change ALL URLs from http://localhost:8080/... to https://external.mydomain.net/..., regardless of their place in the response from the backend server.

In other configurations I have used httpd as a reverse proxy and everything works flawlessly, but for this one particular server I'm stuck with the IIS (there is some content served through the IIS).

Is it possible to configure IIS for such a task ?

in flag
Configure [Tomcat](https://tomcat.apache.org/connectors-doc/common_howto/proxy.html) and/or the application to generate the proper URLs.
stefanu avatar
mn flag
@GeraldSchneider Tomcat does generate the proper URLs; it is an URL rewriting issue on the IIS side.
in flag
Please provide all relevant configuration directives.
stefanu avatar
mn flag
@GeraldSchneider question opdated. thank you.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.