1. The problem I’m having:
Hello! Thank you in advance for your assistance/ideas.
I can’t get (access) logs from Reverse Proxy server blocks to work. I can get all logs into one place if I put logging config into the main Caddyfile
but I would like to have a following outcome:
/etc/caddy/Caddyfile
loging default messages into /var/log/caddy/default.log
Reverse Proxy Server definitions under:
/etc/caddy/Caddyfile.d/subdomain1.caddyfile
logging into:
/var/log/caddy/subdomain1-access.log
so I can have all the access logs for that subdomain in one place.
I appreciate this might not be required for log aggregators but i would be keen to understand how to achieve this outcome with Caddy,
Thanks for any suggestions.
2. Error messages and/or full log output:
No errors, just files aren't being written into. Only one file is being updated with ALL access logs.
3. Caddy version:
2.6.4
4. How I installed and ran Caddy:
dnf install caddy
a. System environment:
Rocky Linux release 9.5 (Blue Onyx)
b. Command:
systemctl start caddy.service
d. My complete Caddy config:
# The Caddyfile is an easy way to configure your Caddy web server.
#
# https://caddyserver.com/docs/caddyfile
# The configuration below serves a welcome page over HTTP on port 80. To use
# your own domain name with automatic HTTPS, ensure your A/AAAA DNS record is
# pointing to this machine's public IP, then replace `http://` with your domain
# name. Refer to the documentation for full instructions on the address
# specification.
#
# https://caddyserver.com/docs/caddyfile/concepts#addresses
{
https_port 8443
servers :443 {
name https
protocols h1 h2
}
servers :80 {
name http
}
servers :8443 {
name 8https
protocols h1 h2
}
log {
output file /var/log/caddy/caddy-default.log {
format json
roll_size 10mb
roll_keep 20
roll_keep_for 720h
}
}
}
http:// {
#log {
# output file /var/log/caddy/http-default.log {
# format json
# roll_size 10mb
# roll_keep 20
# roll_keep_for 720h
# }
#}
# Set this path to your site's directory.
root * /usr/share/caddy
# Enable the static file server.
file_server
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
# Refer to the directive documentation for more options.
# https://caddyserver.com/docs/caddyfile/directives
}
# As an alternative to editing the above site block, you can add your own site
# block files in the Caddyfile.d directory, and they will be included as long
# as they use the .caddyfile extension.
import Caddyfile.d/*.caddyfile
and one of the files from /etc/caddy/Caddyfile.d/
https://cockpit.xxxxx.xxx:8443 {
log {
output file /var/log/caddy/cockpit-access.log {
level DEBUG
format json
roll_size 10mb
roll_keep 20
roll_keep_for 720h
}
}
tls internal
reverse_proxy https://127.0.0.1:9090 {
transport http {
tls
tls_insecure_skip_verify
}
}
}