[英]Access Tomcat root application under different path (on 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 (eg http://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 http://server-name
, which breaks our existing applications. 在我们自己的系统上,我们将Web应用程序作为路径访问(例如,如果我们部署my-app.war,则为http://server-name/my-app
),但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
-file复制到/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, eg 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"
,使用aliases
参数等,提供ROOT目录等的完整路径,但没有一个使我们的WAR文件可以访问/my-app
路径。
Finally, we also tried putting this <Context />
-definition under the <Host />
section in server.xml
, but to no avail. 最后,我们还尝试将此<Context />
-definition置于server.xml
的<Host />
部分下,但无济于事。 Any suggestions? 有什么建议么?
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: 更新 :将以下内容添加到<Host/>
-definition下的server.xml
,我可以在正确的路径下访问my-app
,但似乎EB上的Tomcat现在正在部署我的应用程序两次:
<Context path="/my-app" docBase="ROOT/"></Context>
Although we can now access our app under the desired path, the application is still deployed twice by Tomcat. 虽然我们现在可以在所需的路径下访问我们的应用程序,但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. 从好的方面来说,我们现在可以开始迁移我们的应用程序,以便在访问API时不再使用资源路径,从而实现更清晰,更短的API URL。
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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.