Reverse_proxy with port and path

Hello.
I have two webapps (SafeQ 6) running on Tomcat 9 in my LAN:

  1. print.kstk.lan
  2. print.kstk.lan:9090/end-user/ui/login

When I use reverse_proxy in my Caddyfile for the first one:

print.kostka-skola.cz {
reverse_proxy print.kstk.lan
}

everything is OK and I have my webapp on https://print.kostka-skola.cz Its wonderful!

1. The problem I’m having:

What do I have to do for the second one? Configuration in Caddyfile like this is not working

mprint.kostka-skola.cz {
reverse_proxy print.kstk.lan:9090/end-user/ui/login
}

2. Error messages and/or full log output:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

3. Caddy version:

Caddy v2.8.4

4. How I installed and ran Caddy:

a. System environment:

Ubuntu Server

b. Command:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

5. Links to relevant resources:

I think for tomcat if the app has a specific virtual directoy as base path you can do this:

app1.example.com {
		rewrite * /end-user/ui/login{uri}
		reverse_proxy tomcat.example.com:8080
}

This will prepend the path to all requests. Or so Ive heard from a tomcat user I had to do with before. Feel free to correct me if this is wrong.

1 Like

Thank you for your answer. When I use in my Caddyfile

mprint.kostka-skola.cz {
rewrite * /end-user/ui/login{uri}
reverse_proxy print.kstk.lan:9090
}

it generate address mprint.kostka-skola.cz/end-user/ui/login and I get an error: ERR_TOO_MANY_REDIRECTS

Where’s it redirecting to?

It might need some different/special handling depending on how it works.

Try enabling the debug global option, running curl -vL on your site, and posting the output of both.

1 Like