How to solve status 403 in Caddy version 2

1. Caddy version (caddy version):

2

2. How I run Caddy:

systemctl start caddy

a. System environment:

CentOS 8

b. Command:

systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

www.example.com {
    log {
        output file /var/log/caddy/caddy.log
    }
    file_server * browse {
        root /var/www/html
    }
}

3. The problem I’m having:

Instead of responding with status 200 and the web page index.html,. Caddy responds with status 403, forbidden.

4. Error messages and/or full log output:

{"level":"error","ts":1598277948.5061944,"logger":"http.log.access.log0","msg":"handled request","request":{"method":"GET","uri":"/","proto":"HTTP/2.0","remote_addr":"1.2.3.4:58953","host":"www.example.com","headers":{"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Cache-Control":["max-age=0"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"],"Accept-Language":["en-US,en;q=0.5"]},"tls":{"resumed":false,"version":772,"ciphersuite":4865,"proto":"h2","proto_mutual":true,"server_name":"www.example.com"}},"common_log":"1.2.3.4 - - [24/Aug/2020:14:05:48 +0000] \"GET / HTTP/2.0\" 403 0","duration":0.000274589,"size":0,"status":403,"resp_headers":{"Server":["Caddy"]}}

5. What I already tried:

file_server * browse

6. Links to relevant resources:

Is /var/www/html readable by user caddy?

Maybe provide output of following command:

ls -lha /var/www/html

Depends on your setup, maybe adding user caddy to the group owner of that directory is the quickest fix.

usermod –aG <group> caddy
1 Like

I made the entire directory owned by caddy:

chown -R caddy:caddy /var/www

I also made /etc/caddy/Caddyfile as simple as possible:

www.example.com
root * /var/www/html
log {
    output file /var/log/caddy/caddy.log
}
file_server

With this Caddyfile, I am getting status 404, not found.

I get the idea it is not looking where I think it is looking.

Is your caddyfile with upper case C as shown above?

What are the contents of your /var/www/html directory? Do you have an index.html in there?

By default, Caddy’s file server will look for an index.html or an index.txt file in the root when you request the / path.

The Caddyfile has an uppercase C in its name.

The /var/www/html contains index.html.

I have replaced Caddy with Nginx to avoid spending any more time on it.

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