Path and port reverse proxy

1. The problem I’m having:

This is my first project that uses caddy.
I’m trying to achieve one of these two behaviors, using two different Caddyfiles
First behavior:

  1. https://xxx.ddns.net should be resolved as https://xxx.ddns.net:8080
  2. https://xxx.ddns.net:1234 should be resolved as https://xxx.ddns.net:5678
    The first one works, the second one doesn’t, it reports error SSL_ERROR_RX_RECORD_TOO_LONG

Second behavior:

  1. https://xxx.ddns.net should be resolved as https://xxx.ddns.net:8080
  2. https://xxx.ddns.net/hello should be resolved as https://xxx.ddns.net:1234
    The first one works, the second one doesn’t, it reports error 404

2. Error messages and/or full log output:

In the case of the first behavior, https://xxx.ddns.net:1234 leads to a browser page with error SSL_ERROR_RX_RECORD_TOO_LONG

In the case of the second behavior, https://xxx.ddns.net/hello/ leads to a browser page with a 404 error or a JSON file containing only “not found”

3. Caddy version:

I downloaded the windows amd64 binary without plugin available here https://caddyserver.com/download on 18/02/2026

4. How I installed and ran Caddy:

a. System environment:

Windows 11

b. Command:

Running caddy with bat file:
cd J:\Caddy
caddy run

d. My complete Caddy config:

First behavior:

{
email   me@outlook.com 
}

xxx.ddns.net:1234 {

reverse_proxy localhost:5678

}

xxx.ddns.net {

reverse_proxy localhost:8080

}

Second behavior (I tried replacing the first one, closing and opening caddy again):

{
email   me@outlook.com 
}

xxx.ddns.net {
    handle /hello/* {
        reverse_proxy localhost:1234
    }

    handle /* {
        reverse_proxy localhost:8080
    }
}

For the second behavior I also tried:

{
email   me@outlook.com 
}

xxx.ddns.net {
	reverse_proxy /hello/* localhost:1234
	reverse_proxy localhost:8080
}

5. Links to relevant resources:

https://caddyserver.com/docs/caddyfile/patterns#reverse-proxy
https://dev.to/vizalo/path-based-reverse-proxying-with-caddy-3gjm

This is serving HTTP not HTTPS, which is why you get the SSL error when you try to connect with HTTPS. Use https://xxx.ddns.net:1234 instead in the Caddyfile.

This doesn’t handle /hello as you tried to fetch, only /hello/ . It will be passed to the other reverse proxy instead, which is returning the 404, I guess.

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