Reverse_proxy header_down on location header... or something equivalent?

1. Caddy version (caddy version):

v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

2. How I run Caddy:

In docker. Currently just manually editing the caddyfile and running caddy run.

a. System environment:

Docker 20.10.6

b. Command:

caddy run --config /etc/caddy/Caddyfile

d. My complete Caddyfile or JSON config:


redir /rstudio /rstudio/

route /rstudio/* {
        uri strip_prefix /rstudio

        reverse_proxy {
                header_down  Location ([^:]+://[^:]+(:[0-9]+)?/   ./

3. The problem I’m having:

rstudio returns absolution location paths in redirects (notably when logging in). I’m trying to manipulate locations to be relative.

Going to http://localhost/rstudio/ redirects to http://localhost/auth-sign-in?appUri=%2F
I want it to redirect to ./rstudio/auth-sign-in?appUri=%2F

4. Error messages and/or full log output:


5. What I already tried:

mostly just different things with header_down in reverse_proxy.

6. Links to relevant resources:


You’re essentially running into this:

I have to recommend using a subdomain for that app instead of trying to proxy it under a subpath. On most linux distributions, *.localhost will also resolve to, so you could use rstudio.localhost to differentiate it from other apps.

If the app has a “base path” configuration or equivalent, you might use that to avoid needing to do additional manipulations. If it doesn’t, then it’ll always be a struggle to fix all the paths it responds with (including CSS/JS paths in HTML, redirects, etc).

My apologies, I should have been more clear about my environment and constraints. I’m dev’ing locally, but it’s for servers on an intranet. Our cert management is a somewhat tedious process so I’m attempting to use basepath/subfolder/subpath instead of subdomains because we’re trying a variety of ide’s. so far rstudio server is the only one that doesn’t use relative redirects or a basepath configuration.

I was finally able to get redirects to work by fixing my header_down as below. It attempts to strip the protocol, hostname, port, and initial slash from the location header and replace it with a relative ./
This fix won’t work with content, just a redirect. I also don’t know how robust this regex is, so it may need additional tweaking.

header_down  Location ([^:]+://[^:]+(:[0-9]+)?/)  ./

As a followup note. For apps that are expected to work with nginx’s proxy_pass directive for subpaths/folders (like rstudio server), manipulating location and refresh headers should be all that’s required as their docs indicate that’s all proxy_pass does. The key is to get the right header manipulation regex.

NGINX proxy_pass Reference

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