Help with tomcat reverse proxy

1. Caddy version (caddy version):

2.4.5

2. How I run Caddy:

caddy run --watch

a. System environment:

REHL 8

b. Command:

caddy run --watch

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

{
        debug
        http_port 8080
        https_port 8443
}

:8443 {
        tls /my_home/certs/server.pem /my_home/certs/server.key
        encode zstd gzip
        root * /my_home/web
        templates
        file_server browse
        reverse_proxy /apps/* localhost:8888
}

3. The problem I’m having:

Unable to get to Tomcat’s default page and Tomcat manager.

4. Error messages and/or full log output:

There are no error messages in the logs.

5. What I already tried:

I can access the root https://hostname:8443/ and see the index.html
When I try https://hostname:8443/apps I get 404
When I try https://hostname:8443/apps/ I get Tomcat’s 404 error "The requested resource [/apps/] is not available

I’ve tried using “route” and using “ui strip_prefix” but couldn’t get the results I was expecting.

6. Links to relevant resources:

You could try this:

{
	debug
	http_port 8080
	https_port 8443
}

:8443 {
	tls /my_home/certs/server.pem /my_home/certs/server.key
	encode zstd gzip

	handle_path /apps* {
		reverse_proxy localhost:8888
	}

	handle {
		root * /my_home/web
		templates
		file_server browse
	}
}

Using handle blocks makes sure that reverse_proxy and file_server routes are mutually exclusive. And handle_path has built-in uri strip_prefix logic.

That was because /apps doesn’t match /apps/* because your matcher expects at least a slash after /apps.

It’s worth mentioning though, not all backend apps are properly set up for, or configured to handle requests to a different base path. See this article for additional reading on the topic:

Thank you for the quick response.
With your recommended config changes I’m able to access the Tomcat default (home) page however, when I click on “Manager App” or any other links on that default page it fails. I experienced similar issue using “handle” with “strip_prefix”. I’ll go through the article that you’ve shared, maybe the solution will be in there.

1 Like

The solution is really “just use a subdomain for it”, if you can’t reconfigure the tomcat app to handle /apps paths.

Thank you!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.