Setting Up Logging - error received

1. The problem I’m having:

I would like to enable logging so that I can see traffic to my sites. I attempted to read the documentation but I may not be reading it correctly. I added the log block below to my config, restarted the service and it fails restart stating that it couldn’t recognize the directive: output.
Please keep in mind that I am not a developer and do not understand json. I simply attempted to read the cryptic Caddy documentation and try to configure Caddy. I am attempting to self-host at home both my reverse proxy server and web server. Caddy is installed on one Red Hat server and my web server is on a separate server.

2. Error messages and/or full log output:

Error: adapting config using caddyfile: /etc/caddy/Caddyfile:104: unrecognized directive: output

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

dnf install ‘dnf-command(copr)’
dnf copr enable @caddy/caddy
dnf install caddy

a. System environment:

Red Hat Enterprise Linux release 8.9 (Ootpa)

b. Command:

systemctl enable --now caddy

c. Service/unit/compose file:

# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

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

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

[Install]
WantedBy=multi-user.target


d. My complete Caddy config:

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.
{
        debug
}

www.edscloud.org {
        # 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 to vm server teststuff
        reverse_proxy "webserverip":8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

edscloud.org {
        redir https://www.{host}{uri}
}

rss.edscloud.org {
        # 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 to vm server teststuff
        reverse_proxy "webserverip":81

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

################################################################
www.androidsdream.net {
        # Enable the static file server.
        #        file_server

        reverse_proxy "webserverip":8080
}

androidsdream.net {
        redir https://www.androidsdream.net{uri}
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

#
log {
        output file /var/log/caddy/access.log {
                roll_size 1gb
                roll_keep 5
                roll_keep_for 720h
        }
}

5. Links to relevant resources:

Directives go inside site blocks.

Basically the Caddyfile parser is seeing log as a domain name, and then output as a directive, which is wrong. You have to move log into your sites.

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