Logging with caddy v2

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

a. System environment:

ubuntu 18.04

b. Command:

c. Service/unit/compose file:

d. My complete Caddyfile or JSON config:

https://example.net, example.net {
        root * /var/www/rtl.example.net/current/public
        #log /var/log/caddy/access.log
        #errors /var/log/caddy/error.log
        #gzip
        #browse
        file_server
        # Add trailing slash for directory requests
        @canonicalPath {
                file {
                        try_files {path}/index.php
                }
                not path */
        }
        redir @canonicalPath {path}/ 308

        # If the requested file does not exist, try index files
        @indexFiles {
                file {
                        try_files {path} {path}/index.php index.php
                        split_path .php
                }
        }
        rewrite @indexFiles {http.matchers.file.relative}

        # Proxy PHP files to the FastCGI responder
        @phpFiles {
                path *.php
        }
        reverse_proxy @phpFiles unix:/run/php/php7.3-fpm.sock {
                transport fastcgi {
                        split .php
                }
        }
        log {
                output file /var/log/caddy/access.log
                format single_field common_log
        }
}

3. The problem I’m having:

nothing gets logged to the /var/log/caddy/access.log.

What i’m trying to do is get error logs. But not found any useful examples in the docs on how to do this. I read the pages on logging. But other than options for logging and customization there is nothing on how to turn it on or use it.

4. Error messages and/or full log output:

5. What I already tried:

read the logging docs

6. Links to relevant resources:

1 Like

To do code formatting, use ``` (three backticks, not just one) on separate lines before and after your config. I went ahead and fixed the formatting for you (mostly for my sanity :sweat_smile:).

Your unix socket address is incorrect, it should be this:

unix//run/php/php7.3-fpm.sock

You can see an example of that here:

Also FYI, you can replace all of this:

        # Add trailing slash for directory requests
        @canonicalPath {
                file {
                        try_files {path}/index.php
                }
                not path */
        }
        redir @canonicalPath {path}/ 308

        # If the requested file does not exist, try index files
        @indexFiles {
                file {
                        try_files {path} {path}/index.php index.php
                        split_path .php
                }
        }
        rewrite @indexFiles {http.matchers.file.relative}

        # Proxy PHP files to the FastCGI responder
        @phpFiles {
                path *.php
        }
        reverse_proxy @phpFiles unix:/run/php/php7.3-fpm.sock {
                transport fastcgi {
                        split .php
                }
        }

with just this:

php_fastcgi unix//run/php/php7.3-fpm.sock

As for your log directive, it looks correct to me. I think you probably had either some startup or Caddy parse errors from the incorrect unix socket address. If you’re running with the systemd service (which you didn’t fill out in the template) then you can run journalctl -u caddy to see the stdout logs from Caddy. It might reveal what’s going wrong.

1 Like

It indeed was an issue with my reverse proc.
I was expecting caddy to throw some error. But i was only able to see the error with caddy run

1 Like

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