Caddy-ratelimit example: Caddyfile:6: unrecognized directive: distributed

1. Output of caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

Downloaded from Download Caddy
Using Linux amd64
Selected mhold/caddy-ratelimit plugin

2. How I run Caddy:

$ ./caddy run

a. System environment:

Ubuntu 22.04

b. Command:

./caddy run

d. My complete Caddy config:

{
	order rate_limit before basicauth
}

rate_limit {
	distributed
	zone static_example {
		key    static
		events 100
		window 1m
	}
	zone dynamic_example {
		key    {remote_host}
		events 2
		window 5s
	}
}

respond "I'm behind the rate limiter!"

3. The problem I’m having:

Attempting to run the sample code here: GitHub - mholt/caddy-ratelimit: HTTP rate limiting module for Caddy 2

4. Error messages and/or full log output:

$ ./caddy run
2022/11/06 16:28:35.717	INFO	using adjacent Caddyfile
Error: adapting config using caddyfile: Caddyfile:6: unrecognized directive: distributed

5. What I already tried:

Simplified the config, still no good.

{
	order rate_limit before basicauth
}

rate_limit {
	zone test {
		key    {remote_host}
		events 2
		window 5s
	}
}

respond "I'm behind the rate limiter!"
$ ./caddy run
2022/11/06 16:28:35.717	INFO	using adjacent Caddyfile
Error: adapting config using caddyfile: Caddyfile:6: unrecognized directive: zone

That’s an invalid Caddyfile. You must tell Caddy a site address for it to work correctly. With your current config, it thinks rate_limit is your site address (i.e. domain name) you want to serve, so things inside of that like distributed are parsed as if they’re directives.

See the docs for how the Caddyfile is structured:

2 Likes

Got it, rate_limit needs to be inside of a site address block. It’s working now!

As a complete newbie coming from nginx, that tiny detail just wasn’t super obvious in this example: GitHub - mholt/caddy-ratelimit: HTTP rate limiting module for Caddy 2

Although I do absolutely love the briefness of Caddyfiles over JSON or nginx config. Less lines, less human error.

1 Like

Yeah, the :80 there is the site address.

I tend to always have people use the longer form with braces because it’s less ambiguous. Feel free to propose that change on GitHub :+1:

1 Like

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