Per site log logging all sites

1. My Caddy version (caddy version):

v2.0.0-beta.20 h1:oUNG1uh0UV8LWLlAVDZolFzk112++V/pxY+fF0HLmlY=

2. How I run Caddy:

systemd

a. System environment:

Ubuntu 18.04.4

c. Service/unit/compose file:

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

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile --resume --environ
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --adapter 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:

domain1.com {
        root * /var/lib/caddy/domain1.com
        file_server
        log {
                output file /var/log/caddy/domain1.com
        }
}

domain2.com {
        root * /var/lib/caddy/domain2.com
        file_server
        log {
                output file /var/log/caddy/domain2.com
        }
}

www.domain2.com {
        redir https://domain2.com{uri}
}

domain3.com {
        redir https://www.domain3.com{uri}
}

www.domain3.com {
        root * /var/lib/caddy/www.domain3.com
        file_server
        log {
                output file /var/log/caddy/www.domain3.com
        }
}

(had to retract the domain names as they don’t belong to me)

3. The problem I’m having:

All requests end up being logged in all logfiles

$ ls -l /var/log/caddy
total 30224
-rw-r--r-- 1 caddy caddy 10307648 Mar 29 08:51 domain1.com
-rw-r--r-- 1 caddy caddy 10307648 Mar 29 08:51 domain2.com
-rw-r--r-- 1 caddy caddy 10307648 Mar 29 08:51 www.domain3.com
$ grep domain3.com /var/log/caddy/domain1.com | wc -l
258
$ grep domain3.com /var/log/caddy/domain2.com | wc -l
258
$ grep domain3.com /var/log/caddy/www.domain3.com | wc -l
258
$

Hello –

I am not able to reproduce that behavior. I set those domains in my hosts file to point to localhost and then used your Caddyfile verbatim and the logs are going to their proper files, as expected.

Can you please post the contents of each of the log files? (And please don’t redact, we have rules about this for good reason – doesn’t matter who owns the domain names. If you want us to be helpful we need the already-public information to not be redacted, please.)

As another suggestion, try running Caddy manually without the service file or any of the unnecessary flags to make sure that’s not getting in the way.

Edit: Someone else recently posted about a similar issue, but I have been unable to reproduce that problem as well… hmm. (Edit: I’ve since been able to reproduce it, but it was likely a different issue – impossible to know for sure without your complete and unredacted Caddyfile.)

I’ve tried starting over with a new Caddyfile and changing everything to to my own domains - and I couldn’t reproduce it either. In the process, I deleted the autosave.json file.

When I switched back to the old Caddyfile, everything worked as expected. Maybe deleting this json file solved the problem? Sadly, I didn’t keep a copy of the old file.

So it sounds like you’re running Caddy wrong for what you need – try removing the --resume flag.

I’ve taken the startup script from here: dist/caddy.service at master · caddyserver/dist · GitHub

Right, but do you know what it means/does? :slight_smile:

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