How to set up multiple exploded webapps (outside of $CATALINA_BASE/webapps) as ROOT in Tomcat 8?

huangapple go评论81阅读模式
英文:

How to set up multiple exploded webapps (outside of $CATALINA_BASE/webapps) as ROOT in Tomcat 8?

问题

以下是翻译好的内容:

这是我需要的摘要:

  1. 在Tomcat 8实例中运行多个应用程序。
  2. 这些应用程序是解开的(未打包为WAR),需要位于/misc/目录下。
  3. 它们需要作为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 &quot;%r&quot; %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:

  1. Run multiple apps in a Tomcat 8 instance.
  2. These apps are exploded (not packaged as a WAR), and need to be in /misc/
  3. 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:

&lt;Host name=&quot;qa01&quot; appBase=&quot;qa01&quot;
      unpackWARS=&quot;true&quot; autoDeploy=&quot;true&quot;&gt;
    &lt;Alias&gt;qa01.example.com&lt;/Alias&gt;
    &lt;Valve className=&quot;org.apache.catalina.valves.AccessLogValve&quot; directory=&quot;logs&quot;
           prefix=&quot;qa01_access_log&quot; suffix=&quot;.txt&quot;
           pattern=&quot;%h %l %u %t &amp;quot;%r&amp;quot; %s %b&quot; /&gt;
&lt;/Host&gt;

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.

&lt;Context docBase=&quot;/misc/qa01/webapps/ROOT/&quot;&gt;
&lt;/Context&gt;

Anyone has any idea on what I'm doing wrong?

答案1

得分: 1

我建议:

  1. 在Tomcat的webapps目录中使用软链接。指向您部署的Web应用程序。假设它们遵循Java EE Servlet标准。请阅读这个答案

  2. 明智地使用&lt;tomcat-home&gt;/conf/context.xml配置文件来管理ROOT上下文。请在这里和这里阅读有关这个context.xml的更多信息。

英文:

I suggest:

  1. 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.

  2. Use &lt;tomcat-home&gt;/conf/context.xml configuration file wisely to manage the ROOT context. Please read more about this context.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

&lt;Context path=&quot;&quot;
        antiResourceLocking=&quot;false&quot; /&gt;

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.

&lt;Context docBase=&quot;/misc/qa01/webapps/ROOT/&quot;&gt;
&lt;/Context&gt;

huangapple
  • 本文由 发表于 2020年10月22日 02:45:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64469822.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定