I get the error " unrecognized directive.. " for a simple reverse proxy

1. Caddy version: 2.3.0-alpine

2. How I run Caddy: by docker-compose.yml

a. System environment: Linux Ubuntu 18.04.05 LTS

b. Command:

sudo docker-compose up -d

c. Service/unit/compose file:

> version: '3.8'
> 
> services:
>  caddy:
>     image: caddy:2.3.0-alpine
>     container_name: caddy
>     ports:
>     - 80:80
>     - 443:443
>     volumes:
>     - caddyfile:/etc/caddy
>     - caddy_data:/data
>     - caddy_config:/config    
>     networks:
>     - main
>     restart: unless-stopped
> 
> networks:
>  main:
>   external: true
> 
> volumes:
>   caddyfile:
>   caddy_data:
>   caddy_config:

d. My complete Caddyfile or JSON config:

fish.me, todo.fish.me

todo.fish.me {
	reverse_proxy todo-server:8080
}

3. The problem I’m having:

Coming from NGINX to Caddy I’m trying to setup a simple reverse proxy for my docker service todo-server but for some reason when I call caddy reload in the same directory as the etc/caddy/Caddyfile inside the docker container I get the error below.

4. Error messages and/or full log output:

INFO using adjacent Caddyfile
reload: adapting config using caddyfile: Caddyfile:3: unrecognized directive: todo.fish.me

Your config should probably look like this:

fish.me, todo.fish.me {
	reverse_proxy todo-server:8080
}

The problem you’re running into is that if you have more than one site defined, then all sites need to use braces. What’s happening is that because your first “site” (your first line of config) doesn’t have a brace, it starts reading stuff that follows as directives, but that won’t work because todo.fish.me isn’t a directive. See the docs:

Well I think the docs is a bit confusing and lacking as I’m finding all informations from there.

The quick start section here says that “The first thing to type in a Caddyfile is your site’s address:” which I did in my Caddyfile as you see and I dont know why because the docs isn’t explaining it.

I think this section about reverse-proxy is lacking better examples and explanations too.

But I figured out from stackoverflow and reddit in the end.

It’s explained right here:

When there is only one site block, the curly braces (and indentation) are optional. This is for convenience to quickly define a single site.

To configure multiple sites with the same Caddyfile, you must use curly braces around each one to separate their configurations:

It’s a quick-start. That’s not its job. That page aims to just “get you running quickly” and if you follow it to the letter, you will get there.

If you want to go deeper, you need to read further in the docs.

2 Likes

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