1. Caddy version (caddy version
):
v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=
2. How I run Caddy:
a. System environment:
Official Alpine Docker image/container from Docker Hub.
b. Service/unit/compose file:
caddy:
image: caddy:alpine
container_name: caddy
restart: unless-stopped
labels:
- com.centurylinklabs.watchtower.enable=true
ports:
- "4443:443"
- "8080:80"
networks:
- redacted
volumes:
- ./caddy/data:/data
- ./caddy/config:/config
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
- /mnt/media/websites:/www/websites:ro
env_file: ./envs/common.env
c. My complete Caddyfile or JSON config:
http:// {
basicauth /* {
username password
}
handle_errors {
rewrite * /{http.error.status_code}
reverse_proxy https://http.cat
}
handle {
root / /www/websites/
file_server
}
}
3. The problem I’m having:
With the above Caddyfile, there is no prompt for basic auth. You’re immediately displayed the 401 status page (in this case that is https://http.cat/401). The handle_errors
solution is from this github issue.
4. Error messages and/or full log output:
N/A
5. What I already tried:
Commenting or removing
handle_errors {
rewrite * /{http.error.status_code}
reverse_proxy https://http.cat
}
resolves the issue, so there seems to be an issue with order of operations preventing the auth prompt from ever appearing.
I’m open to either the order of operations being changed at the source or a different solution to error handling that would resolve this.