Unrecognized directive: uri

1. Caddy version (caddy version):

(devel)

2. How I run Caddy:

I’m running Caddy in a Docker container. Here’s the docker-compose.yml:

version: '3'

services:
  caddy-web:
    image: caddy/caddy
    ports:
            - 80:80
            - 443:443
    volumes:
            - ../commerceowl/html/:/var/www/html/
            - ./config/Caddyfile:/etc/caddy/Caddyfile
    logging:
        options:
            max-size: 50m

a. System environment:

Docker version 19.03.1, build 74b1e89
docker-compose version 1.17.1, build unknown

b. Command:

docker-compose up

c. Service/unit/compose file:

docker-compose.yml:

version: '3'

services:
  caddy-web:
    image: caddy/caddy
    ports:
            - 80:80
            - 443:443
    volumes:
            - ../commerceowl/html/:/var/www/html/
            - ./config/Caddyfile:/etc/caddy/Caddyfile
    logging:
        options:
            max-size: 50m

d. My complete Caddyfile or JSON config:

{
  email hgezim@example.com
  acme_ca https://acme-v02.api.letsencrypt.org/directory
  #acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}

https://www.commerceowl.com {
  file_server {
    root /var/www/html
  }
  try_files {path}.html {path}
  encode gzip zstd
  log
}

commerceowl.com, sellwithrecipes.com, www.sellwithrecipes.com {
  redir https://www.commerceowl.com{uri}
}

https://help.commerceowl.com {
  # this is erroring for some reason
  uri /en/* strip_prefix /en
  redir https://www.commerceowl.com/support{uri}
}

3. The problem I’m having:

I get this error when running docker-compose up:

caddy-web_1  | 2021/06/19 13:02:52.047	INFO	using provided configuration	{"config_file": "/etc/caddy/Caddyfile", "config_adapter": "caddyfile"}
caddy-web_1  | run: adapting config using caddyfile: /etc/caddy/Caddyfile:22: unrecognized directive: uri
caddy_caddy-web_1 exited with code 1

4. Error messages and/or full log output:

$ docker-compose up
Creating network "caddy_default" with the default driver
Creating caddy_caddy-web_1 ...
Creating caddy_caddy-web_1 ... done
Attaching to caddy_caddy-web_1
caddy-web_1  | 2021/06/19 13:02:52.047	INFO	using provided configuration	{"config_file": "/etc/caddy/Caddyfile", "config_adapter": "caddyfile"}
caddy-web_1  | run: adapting config using caddyfile: /etc/caddy/Caddyfile:22: unrecognized directive: uri
caddy_caddy-web_1 exited with code 1
$

5. What I already tried:

I tried leaving the URL without a matcher: uri strip_prefix /en and I get the same error:

$ docker-compose up
Creating network "caddy_default" with the default driver
Creating caddy_caddy-web_1 ...
Creating caddy_caddy-web_1 ... done
Attaching to caddy_caddy-web_1
caddy-web_1  | 2021/06/19 13:08:16.792	INFO	using provided configuration	{"config_file": "/etc/caddy/Caddyfile", "config_adapter": "caddyfile"}
caddy-web_1  | run: adapting config using caddyfile: /etc/caddy/Caddyfile:22: unrecognized directive: uri
caddy_caddy-web_1 exited with code 1
$

6. Links to relevant resources:

Which version, exactly? It matters.

You should be using the caddy image, not caddy/caddy. See the docs on Docker Hub, and don’t forget to set up volumes for /data and /config. Without those volumes, your certificates and keys will be lost any time you recreate the containers. That’s not good.

You should be using the root directive, not the root option of file_server. This is because try_files also needs to know the root to be able to function properly.

1 Like

Thanks for the response @francislavoie!

Which version, exactly? It matters.

I was surprised I got (devel) from the version command as well.

I ended up doing a docker-compose pull which pulled a new image and fixed the issue.

don’t forget to set up volumes for /data and /config

Hah…found that out the hard way yesterday :smiley:

You should be using the root directive, not the root option of file_server. This is because try_files also needs to know the root to be able to function properly.

You’re preempting my questions here :sweat_smile: … thanks so much!

1 Like

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