1. Caddy version (caddy version
):
v2.4.6
2. How I run Caddy:
systemd
a. System environment:
Arch, systemd
b. Command:
N/A
c. Service/unit/compose file:
N/A
d. My complete Caddyfile or JSON config:
{
admin off
email name@mysite.com
key_type rsa4096
}
(standards) {
encode zstd gzip
file_server
header {
Referrer-Policy "same-origin"
Cache-Control "max-age=31536000"
X-XSS-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
X-Frame-Options "deny"
}
tls {
protocols tls1.2 tls1.3
}
}
mysite.com, www.mysite.com {
root * /var/www/mysite
import standards
basicauth /secret/* {
foo (hashed-password-here)
}
handle_errors {
redir https://mysite.com
}
}
3. The problem I’m having:
Others have posted about the “handle_errors” directive conflicting with the “basicauth” directive since 2019, and to the credit of the Caddy team, a fix was implemented, but I’m still experiencing the issue on a brand new Arch server with the latest Caddy release, adhering to the official Caddy documentation.
4. Error messages and/or full log output:
curl -I https://mysite.com/secret
responds:
HTTP/2 302
location: https://mysite.com
server: Caddy
www-authenticate: Basic realm="restricted"
In a browser, mysite.com/secret redirects to mysite.com
5. What I already tried:
If I remove the handle_errors directive, it responds:
HTTP/2 401
server: Caddy
www-authenticate: Basic realm="restricted"
In a browser, mysite.com/secret now works.