我一直在使用 ARR 和重写规则来轻松访问我的 Tomcat 应用程序。
就像应用程序运行在:http://localhost:8090/alfresco
重写规则后可以访问:http://localhost/alfresco
这是我一直在使用的完美重写规则的示例:
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(alfresco.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(http?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://localhost:8090/{R:1}" />
</rule>
现在我面临的问题是我有另一台具有相同 tomcat 应用程序名称和端口的本地服务器。现在我想制定一个重写规则,这样当我访问:http://localhost/alfresco1
它应该带我到那个 url 是的服务器:http://172.23.1.168:8090/alfresco
最佳答案
您可以使用以下配置:
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="^(alfresco)1/?(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(http?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://172.23.1.168:8090/{R:1}/{R:2}" />
</rule>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="^(alfresco)/?(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(http?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://localhost:8090/{R:0}" />
</rule>
它的作用:
- 如果 url 以
alfresco1
开头,它将使用{R:1 }
和{R:2}
back references . - 如果 url 以
alfresco
开头,它会使用匹配的字符串 back reference 将其重写为http://localhost:8090:8090/alfresco/requested_path
.
此配置基于the fact那:
The rules are evaluated in the same order in which they are specified
规则在配置文件中定义的顺序很重要。
关于tomcat - 两个 tomcat 服务器使用相同的端口,为 iis 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17185286/