阅读背景:

在不同路径下访问Tomcat根应用程序(在AWS / Elastic Beanstalk上)

来源:互联网 

We are deploying a webapp (.war file) from a legacy system where we have full control over our Tomcat instances to Amazon's Elastic Beanstalk instances.

我们正在从遗留系统部署webapp(.war文件),我们可以完全控制我们的Tomcat实例到Amazon的Elastic Beanstalk实例。

On our own systems, we access the web app as a path (e.g. https://server-name/my-app if we deploy my-app.war), but Elastic Beanstalk renames our war-file to ROOT.war and hence makes the web app available under https://server-name, which breaks our existing applications.

在我们自己的系统上,我们访问Web应用程序作为路径(例如,http:// server-name / my-app,如果我们部署my-app.war),但Elastic Beanstalk将我们的war文件重命名为ROOT.war,因此使Web应用程序在http:// server-name下可用,这会破坏我们现有的应用程序。

As per the AWS documentation, we have added a config file under WEB-INF/.ebextensions that copies the following custom context.xml-file to /etc/tomcat7/Catalina/localhost/ROOT.xml:

根据AWS文档,我们在WEB-INF / .ebextensions下添加了一个配置文件,该文件将以下自定义context.xml文件复制到/etc/tomcat7/Catalina/localhost/ROOT.xml:

<?xml version='1.0' encoding='utf-8'?>
<Context displayName="localhost" docBase="" path="/my-app">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

We have tried different versions of this file, e.g. omitting docBase, specifying docBase="ROOT", using the aliases parameter etc., providing the full path to the ROOT directory etc., but none has made our WAR-file accessible under the /my-app path.

我们尝试过此文件的不同版本,例如省略docBase,指定docBase =“ROOT”,使用别名参数等,提供ROOT目录等的完整路径,但没有一个使我们的WAR文件可以在/ my-app路径下访问。

Finally, we also tried putting this <Context />-definition under the <Host /> section in server.xml, but to no avail. Any suggestions?

最后,我们还尝试将此 - 定义放在server.xml的 部分下,但无济于事。有什么建议么?

Update: when adding the following to server.xml under the <Host/>-definition, I'm able to access my-app under the correct path, but it seems that Tomcat on EB is deploying my application twice now:

更新:将以下内容添加到 - 定义下的server.xml时,我可以在正确的路径下访问my-app,但似乎EB上的Tomcat现在正在部署我的应用程序两次:

<Context path="/my-app" docBase="ROOT/"></Context>

2 个解决方案

#1


0  

Although we can now access our app under the desired path, the application is still deployed twice by Tomcat. While this is a minor nuisance for us, I can imagine this being a problem on more resource-tight machines. On the plus side, we can now start migrating our apps to no longer use the resource path when accessing the API, which leads to cleaner and shorter API URLs.

虽然我们现在可以在所需的路径下访问我们的应用程序,但Tomcat仍然会部署该应用程序两次。虽然这对我们来说是一个小麻烦,但我可以想象这在资源紧张的机器上会出现问题。从好的方面来说,我们现在可以开始迁移我们的应用程序,以便在访问API时不再使用资源路径,从而实现更清晰,更短的API URL。

#2


0  

I know it's two years late. But seems like disabling deployOnStartup will do the work.

我知道已经晚了两年。但似乎禁用deployOnStartup将完成工作。

<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="false" deployOnStartup="false">

分享到: