英文:
How to set up multiple exploded webapps (outside of $CATALINA_BASE/webapps) as ROOT in Tomcat 8?
问题
以下是翻译好的内容:
这是我需要的摘要:
- 在Tomcat 8实例中运行多个应用程序。
- 这些应用程序是解开的(未打包为WAR),需要位于/misc/目录下。
- 它们需要作为ROOT运行(即URL末尾没有上下文路径)。
我已经通过使用Tomcat的虚拟主机来实现多个应用程序作为ROOT运行的功能。在/var/lib/tomcat8/conf/server.xml
中,我有:
<Host name="qa01" appBase="qa01"
unpackWARS="true" autoDeploy="true">
<Alias>qa01.example.com</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="qa01_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
然后,我的nginx配置如下:
server {
listen 80;
listen [::]:80;
server_name qa01.example.com;
access_log /var/log/nginx/qa01-access.log;
error_log /var/log/nginx/qa01-error.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
}
目前为止一切正常,我测试过,它绝对指向/var/lib/tomcat8/qa01/ROOT/index.html
。
问题出在当我需要将此应用程序放在/misc/qa01/webapps/ROOT/
中时。
我尝试在/var/lib/tomcat8/qa01/ROOT/META-INF/context.xml
中添加以下内容,但没有成功。
<Context docBase="/misc/qa01/webapps/ROOT/">
</Context>
有人知道我做错了什么吗?
英文:
Here's a summary of what I need:
- Run multiple apps in a Tomcat 8 instance.
- These apps are exploded (not packaged as a WAR), and need to be in /misc/
- They need to run as ROOT (ie no context path at the end of the URL)
I've managed to do the multiple apps as ROOT thing by using Tomcat's virtual host. In /var/lib/tomcat8/conf/server.xml
, I have:
<Host name="qa01" appBase="qa01"
unpackWARS="true" autoDeploy="true">
<Alias>qa01.example.com</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="qa01_access_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>
Then, I have the nginx conf as:
server {
listen 80;
listen [::]:80;
server_name qa01.example.com;
access_log /var/log/nginx/qa01-access.log;
error_log /var/log/nginx/qa01-error.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
}
So far so good, I tested it and it's definitely pointing to /var/lib/tomcat8/qa01/ROOT/index.html
The problem comes when I need this app to be in /misc/qa01/webapps/ROOT/
instead.
I've tried adding /var/lib/tomcat8/qa01/ROOT/META-INF/context.xml
with the following but it didn't work.
<Context docBase="/misc/qa01/webapps/ROOT/">
</Context>
Anyone has any idea on what I'm doing wrong?
答案1
得分: 1
我建议:
-
在Tomcat的
webapps
目录中使用软链接。指向您部署的Web应用程序。假设它们遵循Java EE Servlet标准。请阅读这个答案。 -
明智地使用
<tomcat-home>/conf/context.xml
配置文件来管理ROOT上下文。请在这里和这里阅读有关这个context.xml
的更多信息。
英文:
I suggest:
-
Use soft links in Tomcat
webapps
directory. Pointing to your deployed web applications. Assuming they are following Java EE Servlet standards. Please read this answer. -
Use
<tomcat-home>/conf/context.xml
configuration file wisely to manage the ROOT context. Please read more about thiscontext.xml
here and here.
答案2
得分: 0
弄清楚了我做错了什么(似乎一夜好眠有所帮助)。
我需要将这个内容放在 /var/lib/tomcat8/exampleApp/ROOT/META-INF/context.xml
文件中:
<Context path=""
antiResourceLocking="false" />
然后我需要在 /var/lib/tomcat8/conf/Catalina/exampleApp/ROOT.xml
中配置这个 Context
。这实际上是指向我已展开的 WAR 包所在位置的部分。
<Context docBase="/misc/qa01/webapps/ROOT/">
</Context>
英文:
Figured out what I was doing wrong (seems like a good night of sleep helps).
I need this in /var/lib/tomcat8/exampleApp/ROOT/META-INF/context.xml
<Context path=""
antiResourceLocking="false" />
Then I need to configure the Context
in /var/lib/tomcat8/conf/Catalina/exampleApp/ROOT.xml
. This is the thing that actually points to where my exploded WAR resides.
<Context docBase="/misc/qa01/webapps/ROOT/">
</Context>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论