Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is fallback on a reverse_proxy's lb_policy being parsed properly? #6272

Closed
nperez0111 opened this issue Apr 25, 2024 · 4 comments
Closed

Is fallback on a reverse_proxy's lb_policy being parsed properly? #6272

nperez0111 opened this issue Apr 25, 2024 · 4 comments

Comments

@nperez0111
Copy link

First of all, thank you so much for your work on caddy, absolutely great reverse proxy that I've been relying on for years.

When trying to do a reverse_proxy, using the sample code from the docs does not work:

lb_policy header X-Upstream {
	fallback first
}

Failing to start caddy with this error message:

Error: adapting config using caddyfile: parsing caddyfile tokens for 'reverse_proxy': unexpected token '{', expecting argument, at /etc/caddy/Caddyfile:3

Here is my minimal caddyfile reproduction:

:1234 {
	reverse_proxy http://app:3000 {
		lb_policy header X-Upstream {
			fallback first
		}
	}
}

It seems to me that this fallback option should work and was implemented as part of this PR: #5488

I also tried using this for the query lb_policy and it did not work either. Maybe this is just that the caddyfile is failing to be parsed properly?

If I knew go better, I'd offer my help in fixing it. But, alas, I may never be a gopher, so I will only report it instead.

@nperez0111
Copy link
Author

Ah I was able to get this to work by using the JSON format, so it seems like my suspicion was correct, caddy right now does not parse that format properly in Caddyfile properly. Here is how I got it to work:

Given this starting Caddyfile:

:1234 {
	reverse_proxy http://app:3000 {
		lb_policy header X-Upstream
	}
}

I adapted it to JSON with: caddy adapt --config Caddyfile --pretty > Caddyfile.json

Which resulted in this file:

{
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						":1234"
					],
					"routes": [
						{
							"handle": [
								{
									"handler": "reverse_proxy",
									"load_balancing": {
										"selection_policy": {
											"field": "X-Upstream",
											"policy": "header"
										}
									},
									"upstreams": [
										{
											"dial": "app:3000"
										}
									]
								}
							]
						}
					]
				}
			}
		}
	}
}

I then was able to add a fallback key:

diff --git a/Caddyfile.json b/Caddyfile.json.after
index 66d03e3..e20aa98 100644
--- a/Caddyfile.json
+++ b/Caddyfile.json.after
@@ -14,7 +14,10 @@
 									"load_balancing": {
 										"selection_policy": {
 											"field": "X-Upstream",
-											"policy": "header"
+											"policy": "header",
+                      "fallback": {
+                        "policy": "first"
+                      }
 										}
 									},
 									"upstreams": [

and I checked and it parses & works as expected. So it seems to me the only problem is the Caddyfile format & how it parses that extra block for the fallback field.

@francislavoie
Copy link
Member

francislavoie commented Apr 25, 2024

I can confirm it's broken on v2.7.6, but it's already been fixed on master. I don't remember what we did to fix it though. 🤷‍♂️

Try a build from master, or you can grab the latest artifact from CI https://github.com/caddyserver/caddy/actions/runs/8823591506

We'll be releasing v2.8.0 soon.

@nperez0111
Copy link
Author

I can confirm it's broken on v2.7.6, but it's already been fixed on master. I don't remember what we did to fix it though. 🤷‍♂️

Try a build from master, or you can grab the latest artifact from CI caddyserver/caddy/actions/runs/8823591506

We'll be releasing v2.8.0 soon.

I appreciate your response here. I tried a couple of other 2.7 versions and couldn't find one that works. I'll just use the JSON version for now and wait for 2.8 to release

@mholt
Copy link
Member

mholt commented Apr 25, 2024

We'd actually love for more people to try the beta (what is on master now is practically the beta). You can download the latest build here: https://github.com/caddyserver/caddy/actions/runs/8823591506#artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants