如何让httpd转发到多个tomcat的不同url,包括/?

发布于 2024-10-21 13:45:08 字数 1009 浏览 6 评论 0原文

好的

,所以我在几个 AJP 端口上设置了多个 tomcat 实例,我还在端口 8090 上侦听 Apache httpd(因为我现在有另一个应用程序已经在使用 8080)。

我已经使用 Jk Mount 和以下 vhosts 配置成功将 mydomain.com:8090/demo 和 mydomain.com:8090/preprod 等 URL 映射到各自的 tomcat 实例;

<VirtualHost *:8090>
    JkMount /preprod* preprod
    JkMount /demo* demo
</VirtualHost>

但我还希望“根”地址映射到另一个 tomcat 实例,即实时/生产实例,即我希望 mydomain.com:8090/ 映射第三个 tomcat 实例。

目前,如果我只是在上面的配置中添加一行,则什么也不会发生或改变;

JkMount /* rootwar

如果我浏览到 mydomain.com:8090 我只会得到同样无聊的 apache httpd 登陆页面,让我知道它的运行情况(即 httpd/htdocs 中的 index.html)

是否可以使用 JkMount 将“根”地址重定向到tomcat实例?

我可以看到像 /* 这样的规则也会匹配像 mydomain.com/preprod 这样的 URL,但我希望这些规则按顺序应用,所以如果 /* 出现在末尾,它实际上将是一个“如果它不是其他之一”环境,然后直接到根/生产”

为了清楚起见,我正在尝试设置以下内容;

mydomain.com:8090/preprod --> myApp running in tomcat1
mydomain.com:8090/demo    --> myApp running in tomcat2
mydomain.com:8090         --> myApp running in tomcat3

Ok

So I've got multiple tomcat instances setup on several AJP ports, I also have Apache httpd listening on port 8090 (cos I've got another app already using 8080 at the moment).

I've successfully mapped urls such as mydomain.com:8090/demo and mydomain.com:8090/preprod to their respective tomcat instances using Jk Mount and the following vhosts config;

<VirtualHost *:8090>
    JkMount /preprod* preprod
    JkMount /demo* demo
</VirtualHost>

But I also want the "root" address to map to another tomcat instance, what will become live/production, ie I want mydomain.com:8090/ to map a 3rd tomcat instance.

At the moment nothing happens or changes if I just add to the above config a line;

JkMount /* rootwar

if I browse to mydomain.com:8090 I just get the same boring apache httpd landing page letting me know its running (ie index.html in httpd/htdocs)

Is it possible to use JkMount to redirect the "root" address stuff to a tomcat instance?

I can see that a rule like /* will also match URLs like mydomain.com/preprod but I was hoping the rules are applied in order so if /* appears at the end it effectively would be a "if its not one of the other environments, then direct to root/production"

Just to be clear I'm trying to setup the following;

mydomain.com:8090/preprod --> myApp running in tomcat1
mydomain.com:8090/demo    --> myApp running in tomcat2
mydomain.com:8090         --> myApp running in tomcat3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄情伤 2024-10-28 13:45:08

好吧,事实证明我对 JkMount 东西的失败行为是正确的,因此配置如下:

<VirtualHost *:8090>
    JkMount /preprod* preprod
    JkMount /demo* demo
    JKMount /* root
</VirtualHost>

效果很好,其中带有 /preprod 的 url 会转到 tomcat1,/demo 会转到 tomcat2,其他任何内容都会转到 tomcat3 以获取 root 权限。因此,JkMount /* 根行显然是尝试的最后一个规则,并且只有在没有其他规则与该 url 匹配的情况下才“捕获所有”(因为它的 /*)。

伟大的。

Ok so turns out I was right about the fall through behaviour of the JkMount stuff, thus a config like;

<VirtualHost *:8090>
    JkMount /preprod* preprod
    JkMount /demo* demo
    JKMount /* root
</VirtualHost>

works great, urls with /preprod in them got to tomcat1, /demo goes to tomcat2 and anything else goes to tomcat3 for root. So the JkMount /* root line is obviously the last rule tried and only "catches all" (cos its /*) if none of the other rules have matched the url.

Great.

吃颗糖壮壮胆 2024-10-28 13:45:08

我已经有一段时间没有使用 jk 的东西了,但据我记得这是不可能的。我们通常通过添加一个小的 html 页面来解决这个问题,该页面重定向到 /root jk 挂载点。也许使用 mod_rewrite 规则也可能有效。

像这样的事情:

RewriteEngine on
RewriteRule ^/?(.+)$ /root/$1 

也可以使用更复杂的重写规则隐藏重定向,可以在此处找到示例:

http://www.webmasterworld.com/apache/4277304.htm

I haven't worked with the jk stuff for while but as far as I remember this isn't possible. We usually worked around this by adding a small html page which redirect to the /root jk mount. Maybe using a mod_rewrite rule might also work.

Something like this:

RewriteEngine on
RewriteRule ^/?(.+)$ /root/$1 

It's also possible to hide the redirect with a bit more complex rewrite rules, an example can be found here:

http://www.webmasterworld.com/apache/4277304.htm

云醉月微眠 2024-10-28 13:45:08

好的 - 不是对你的问题的直接答案,但是......另一种选择是在单独的实例中运行每个 demo/preprod 和 prop,每个实例在不同的端口上。

这样做的优点是简化您的配置,但更重要的是您可以对每个实例进行更改(例如退回服务器),而不必担心影响生产实例并将其脱机。

Jetty 也非常适合这种情况,特别是对于运行快速而肮脏的开发和演示实例......您可以编写一个非常简单的脚本,基本上只是指向部署并在某个端口上启动一个 jetty 实例

public static void run(int port, String resourceBase, String descriptor) {
    Server server = new Server(port);

    WebAppContext context = new WebAppContext();
    context.setResourceBase(resourceBase);
    context.setDescriptor(descriptor);
    context.setContextPath("/");
    context.setParentLoaderPriority(true);
    server.setHandler(context);

    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

  • resourceBase是/path/to/webapp
  • 描述符通常是resourceBase+"/WEB-INF/web.xml"

OK - not a direct answer to your question, but...an alternative would be to run each of demo/preprod and prop in separate instances, each on different ports.

This would have the advantage of simplifying your configuration but more importantly you can make changes to each instance (e.g. bouncing the server) without worrying about affecting the production instance and brining it offline.

Jetty is also very good for situations like this, especially for running quick and dirty dev and demo instances....you can write a very simple script that basically just points at a deployment and starts a jetty instance on it on some port:

public static void run(int port, String resourceBase, String descriptor) {
    Server server = new Server(port);

    WebAppContext context = new WebAppContext();
    context.setResourceBase(resourceBase);
    context.setDescriptor(descriptor);
    context.setContextPath("/");
    context.setParentLoaderPriority(true);
    server.setHandler(context);

    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

where

  • resourceBase is /path/to/webapp
  • descriptor is usually resourceBase+"/WEB-INF/web.xml"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文