tomcat - 两个 tomcat 服务器使用相同的端口,为 iis 重写规则

标签 tomcat iis url-rewriting reverse-proxy arr

我一直在使用 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_pa​​th .

此配置基于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/

相关文章:

TheGamesDB.net 的 apache url 重写

.htaccess - 使用 mod_rewrite 将动态 URL 转换为 SEO 友好 URL ??

java - 如何使用 Tomcat 启用静态内容(图像、css、js)的浏览器缓存?

asp.net-mvc - 如何在 IIS 上将两个具有相同 Controller 名称的 asp.net mvc 4 应用程序发布为单个站点

java - 此 Web 应用程序开发的基础知识

iis - IIS快速失败保护中的 "failure"是什么意思?

visual-studio - 使用新的 IIS Express Web 服务器在 Visual Studio 2010 中进行开发?

iis - 无法从 IIS7 中删除 URL 重写

tomcat - 配置 webapp.runner 在开发环境中接受 https 和 http 流量

java - UTF-8 从浏览器而不是应用程序工作