2013-06-19 27 views
1

我一直在使用ARR和重写规则来轻松访问我的Tomcat应用程序。两个使用相同端口的tomcat服务器,为iis重写规则

如果应用程序在运行像: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

应该带我到那个服务器,网址是:http://172.23.1.168:8090/alfresco

+0

是否有任何理由在重写中使用反向引用?我的观点是,'alfresco'是'http:// localhost:8090/alfresco'和'http://172.23.1.168:8090/alfresco'中的一个常量? – cheesemacfly

+0

这是您看到运行的tomcat应用程序名为'alfresco'的主要问题。我上面创建的规则是与名称“alfresco”匹配的网址。所以如果我为'172.23.1.168'创建另一个规则并将其写入规则而不是'localhost',那么仍然会将我带到'172.23.1.168/alfresco'之外的'localhost'。因为它们都具有相同的URL匹配。 – user1788171

回答

1

你可以使用以下配置:

<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:2}back references
  • 如果网址以alfresco开头,则会使用匹配的字符串back reference将其重写为http://localhost:8090:8090/alfresco/requested_path

该配置是基于the fact在于:

的规则在它们被指定

规则在配置文件中定义的顺序相同的顺序进行评估重要。

+0

谢谢,但似乎当我输入“alfresco1”时,它仍然解决为“露天”,因为测试模式也证实。 – user1788171

+0

哦对不起,订购它们的作品,首先你必须编写“alfresco1”规则,它有时会解决到正确的路径 – user1788171

+0

@ user1788171是的,对于这种混淆抱歉。我编辑了我的答案,并改变了模式,以使'/'可选。 – cheesemacfly