Tomcat:一个 webapp 的两个上下文路径 [英] Tomcat: two context paths for one webapp

查看:38
本文介绍了Tomcat:一个 webapp 的两个上下文路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是:我有一个网络应用程序,这个网络应用程序部署到 $TOMCAT_HOME/webapps/XXX 目录.我可以通过 http://localhost:8080/XXX 地址访问它但是,我也想访问 http://localhost:8080/YYY 地址上的网络应用程序.我在 server.xml 中添加了以下内容:

The problem is: I have a web app and this web app is deployed to the $TOMCAT_HOME/webapps/XXX directory. I can reach that on the http://localhost:8080/XXX address BUT, I would like to reach the web app on the http://localhost:8080/YYY address too. I added the following to the server.xml:

<Server>
    <Service>
        <Engine>
            <Host>
                .......
                <Context path="/YYY" docBase="XXX"></Context>
            </Host>
        </Engine>
    </Service>
</Server>

它有所帮助,但 Tomcat 启动了两个 Web 上下文并导致了其他一些问题.是否可以为一个网络应用创建多个"地址?

It helped but the Tomcat started two web contexts and it caused some other problem. Is it possible to create a "multiple" address for one web app?

推荐答案

Web 应用程序的 url 组合如下:

The url of web application is assebled as follows:

PROTOCOL://DOMAIN:PORT/CONTEXT/pagename

PROTOCOL://DOMAIN:PORT/CONTEXT/pagename

在两个不同的地址上有相同的应用程序的解决方案如下:

The solutions for having same app on two distinct address are as follows:

  1. 如果您只想在协议上有所不同(比如在 http 和 https 之间),那么在 server.xml 中只需有 2 个连接器.

  1. If you want to differ only in protocol (let's say between http, and https) then just have 2 connectors in server.xml.

如果您想在 DOMAIN 名称上有所不同,那么这可以在 DNS 级别解决.

if you want to differ in DOMAIN name, then this is solved on DNS level.

如果你想在上下文名称(web应用程序名称)上有所不同,你应该把apache放在前面(mod_proxy或mod_ajp),然后创建一个重写规则(mod_rewrite).假设将所有从 /a/*/b/* 重写为 /c/*

If you want to differ in context name (web application name), you should put apache in front (mod_proxy or mod_ajp) and then create a rewrite rule (mod_rewrite). let's say rewrite all from /a/* and /b/* to /c/*

如果您想在页面名称上有所不同,您应该使用 servlet 映射.

If you want to differ in page name, you should use servlet mappings.

通过mod_proxy把apache放到tomcat前面很容易,网上有很多资源.非常糟糕的是重复应用程序(将所有内容加载两次).

Putting apache in front of tomcat via mod_proxy is very easy, there are multiple resources on the web. Very bad would be to duplicate applications (have everything loaded twice).

至于你的问题,我建议再次在 server.xml 中重复.

As for your question, i would advise agains duplication in server.xml.

<Context docBase="myapp" path="/address1" reloadable="true" />
<Context docBase="myapp" path="/address2" reloadable="true" />

这对内存、会话机制、并发性等都是致命的.

This is killer for memory, as well as for session mechanisms, concurency, etc.

这篇关于Tomcat:一个 webapp 的两个上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆