Basicauth gives: "unauthorized directive Bob"

Hi. Following official docs at basicauth (Caddyfile directive) β€” Caddy Documentation, I tried to setup basic auth but run into the issue, that the directive seems to be different and results this way in an error.

1. Caddy version (caddy version):


2. How I run Caddy:

via docker-compose

    image: caddy:2.1.1-alpine
      - 80:80
      - 443:443

a. System environment:

Docker, alpine

b. Command:

c. Service/unit/compose file:

d. My complete Caddyfile or JSON config:

basicauth /secret/* {
} {
  root * /usr/share/my-app

3. The problem I’m having:

Starting caddy results in the following error:

caddy_1      | {"level":"info","ts":1632204348.0622334,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
caddy_1      | run: adapting config using caddyfile: /etc/caddy/Caddyfile:6: unrecognized directive: Bob

Error: unrecognized directive: Bob

4. Error messages and/or full log output:

unrecognized directive: Bob

5. What I already tried:

other passwords

6. Links to relevant resources:

The directives go inside site blocks, not outside of it. Semantically, consider the question of: how could Caddy which site/host/domain should basicauth apply on if not surrounded by the definition of the site? In your

Also, you have an extra { here in the second line

1 Like

That’s a very old version. Please upgrade to 2.4.5!

Not sure if you have fixed your issue but an alternative way to do it to keep your basicauth outside of your site is to define a code snippet. It helps to manage your users and you can reuse with different sites.
Hope this helps

(basic-auth) {
       basicauth /secrets/* {
              (username) (hashed password)

mytest.mydomain.tld {
      import basic-auth

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