Search code examples
javanginxtomcattomcat8

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


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:

<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?


Solution

  • 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>