lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.74k stars 165 forks source link

Not creating multiple reverse_proxy paths - Caddy2 #149

Closed andrewdhastings closed 4 years ago

andrewdhastings commented 4 years ago

I just might be an idiot and not configuring this right, but when I use the following:

      caddy_0.1_reverse_proxy: "{{upstreams 8069}}"
      caddy_0.2_reverse_proxy: /longpolling "{{upstreams 8072}}"

I only see this

 reverse_proxy /longpolling 172.23.0.4:8072
 }

Then when it runs a min later, it updates to this:

localhost {
reverse_proxy 172.23.0.4:8069
 }

And it goes back and forth...?


Also, this might be unrelated, but I'm trying to also add a redirect for say, www. subdomain. this also gives me an error

      caddy_1: http://www.example.com https://www.example.com
      caddy_1.redir: "{{https:localhost permanent}}"

error is:

 [ERROR] template: :1: expected :=
francislavoie commented 4 years ago
      caddy_1: http://www.example.com https://www.example.com
      caddy_1.redir: "{{https:localhost permanent}}"

I think this should be the following (you only use the {{}} braces for Go templates, this is just a simple string here):

      caddy_1: "http://www.example.com, https://www.example.com"
      caddy_1.redir: "https://localhost{uri} permanent"

And for this one:

      caddy_0.1_reverse_proxy: "{{upstreams 8069}}"
      caddy_0.2_reverse_proxy: /longpolling "{{upstreams 8072}}"

Maybe try this (I think it needs to be 0-indexed?):

      caddy_0.0_reverse_proxy: "{{upstreams 8069}}"
      caddy_0.1_reverse_proxy: /longpolling "{{upstreams 8072}}"

(Also just a note, but in Caddy v2, path matchers are exact match, so you may want /longpolling/* instead, because /longpolling will only match requests to /longpolling and not /longpolling/foo)

andrewdhastings commented 4 years ago

Thanks for the note on the exact matches. I think the fix for redir worked.

However, going to the following still only produced one at a time rotating a min apart.

      caddy_0.0_reverse_proxy: "{{upstreams 8069}}"
      caddy_0.1_reverse_proxy: /longpolling "{{upstreams 8072}}"
francislavoie commented 4 years ago

Oh, right-right-right.

You need to put the number as a suffix when you have multiple of the same. See the example in the README labeled Suffix _<number> isolates directives that otherwise would be grouped:

      caddy_0.reverse_proxy_1: "{{upstreams 8069}}"
      caddy_0.reverse_proxy_2: /longpolling "{{upstreams 8072}}"

Prefix numbers just change the order in which they appear in the output.

(I'm still learning all this just like you are! Sorry for the confusion)

andrewdhastings commented 4 years ago

Perfect, that fixed it!

No worries. Thanks for the help.

lucaslorentz commented 4 years ago

Just to clarify, we have 2 mechanisms that might cause some confusion.

  1. Ordering directives _ prefix. Ordering directives is not necessary that often because Caddyfile directives are executed by Caddy in an order that covers most of the use cases. You only need to order directives when you create a route group.
  2. Isolating directives. _ suffix. This is what you need in your case.

The reason those are different syntaxes is that you could opt for isolating directives, without defining a specific order for it.

andrewdhastings commented 4 years ago

Thanks!

On Mon, May 25, 2020 at 1:10 AM Lucas Lorentz notifications@github.com wrote:

Just to clarify, we have 2 mechanisms that might cause some confusion.

  1. Ordering directives _ prefix. Ordering directives is not necessary that often because Caddyfile directives are executed by Caddy in an order that covers most of the use cases. You only need to order directives when you create a route group.
  2. Isolating directives. _ suffix. This is what you need in your case.

The reason those are different syntaxes is that you could opt for isolating directives, without defining a specific order for it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lucaslorentz/caddy-docker-proxy/issues/149#issuecomment-633416609, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHYGNQZ7XAYLKBTZZBSGXDTRTIKW3ANCNFSM4NJEHPQA .

--

Andrew Hastings The Catalyst Dream Mountain Services P: M: (801) 770-4869 (435) 890-0526 W: E: DreamMtn.Services http://dreammtn.services/ Andrew@DreamMtn.Services andrew@dreammtn.services https://www.facebook.com/DreamMtnServices/ https://twitter.com/DreamMtnService https://www.linkedin.com/in/andrewdhastings https://www.instagram.com/dreammtnservices/

Request a Free Odoo/ERP Consultation http://dreammtn.services/contact-us