V2: reverse proxy but upstream server redirects to nonexistent path

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

a. System environment:

Caddy2 is started by systemd on an ArchLinux host.

b. Command:

caddy run --environ --config /opt/caddy/Caddyfile

c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:

:80 {
	route /ups* {
		uri strip_prefix /ups

3. The problem I’m having:

I am trying to use Caddy2 as a reverse proxy for my UPS monitoring software, located at I also want to put it in a subdirectory under /ups because I will use Caddy to proxy other services. Currently when I access http://server/ups it first redirects to http://server/ups/local and then it redirects again to http://server/local/ which does not exist in Caddy and results in a blank page.

4. Error messages and/or full log output:

5. What I already tried:

	route /ups* {
		uri replace /ups/ /local/


	route /ups* {
		uri replace /ups /local

With these setup the basic http page got served. However, the files are still pointing to http://server/local/xxx.css which do not exist in Caddy. Checking the html source code shows that the files are pointing to the root of the web server.

<link href="/local/styles.258ee99d3b47f8ffdbb1.bundle.css" rel="stylesheet">

Poking around the upstream server shows that the server software is Apache Tomcat/8.5.34

6. Links to relevant resources:

This is the sort of situation where I’d recommend to avoid running the services in subpaths. Instead, I recommend using subdomains or different ports as entrypoints for each service.

Some services being proxied just don’t handle being proxied very well if they expect to be at a certain path. You would need to make sure to rewrite the URLs in the response body as well and that’s a slippery slope (and Caddy doesn’t natively support doing that right now).

It sounds like the backend app is redirecting because it doesn’t know it is being served under a subpath.

Yeah, so the app’s resources need to be in /local/ or whatever.

Frustratingly enough, most backend apps do not like being proxied. Some, like WordPress, you can configure for it, but others you can’t. You’ll have to configure the backend to allow being served in a subpath and/or to disable its redirects.

One of these days I will make this post a wiki post:

Thanks for the responses! I guess I will use a subdomain to proxy this particular app.

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