Precedence between conflicting reverse_proxy

hi,

I’ve two reverse_proxy:

  reverse_proxy /abc* https://abc

and

  reverse_proxy https://everything

My problem is that the reverse_proxy that matches everything takes precedence on the more specific one, regardless of the order in which the two directives appear in Caddyfile.

I don’t want to use route or handle because I would like to import the configuration of the two independently.

So my current solution is to use:

@not_abc {
  not path /abc*
}
reverse_proxy @not_abc https://everything

This works but it is again coupling the two.
Why reverse_proxy are not sorted from the more specific to the less specific? Is there a why to do that?

Thanks

That shouldn’t be the case. What’s your full Caddyfile, what version of Caddy are you using?

You can use the caddy adapt command to look in the JSON to see in which order they get evaluated.

If you’d use the help thread template, that helps us help you :slightly_smiling_face:

OK, I’ve figured it out: reverse_proxy https://everything was actually inside a route, so it was taking precedence on the other one even if less specific.
The proper solution is to put also the other one inside a more specific route, something like:

  route /abc* {
    reverse_proxy https://abc
  }
  route {
    reverse_proxy https://everything
  }

This works perfectly.
I’ve understood it looking at the JSON configuration, thank you for the hint.
Best regards

The route is likely not necessary there, but it depends on what the rest of your Caddyfile is doing. Next time, please post your whole Caddyfile, because it’s impossible to accurately help without seeing the whole thing.

I needed the route on the “everything” because I want to first serve files, and then the reverse_proxy, so in full it is more like that:

  route /abc* {
    reverse_proxy https://abc
  }
  @static_file {
    file
    not path /
  }
  route {
    file_server @static_file
    reverse_proxy https://everything
  }

This works as intended but maybe there is another simpler way to achieve the same.

1 Like

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