How to Create Log to Self Audit who Connects to my Server

1. Caddy version (caddy version): Caddy 2

2. How I run Caddy:

I’m running Caddy from Windows 10 Pro as a Reverse Proxy. Trying to figure out how to add a log to my Caddy file so I can self audit who connects to my server.

a. System environment:

OS, relevant versions, systemd? Docker? etc.
Windows 10 Pro where I have Caddy V2 and Emby Server installed.

b. Command:

Caddy Run via a caddy.bat file to automatically start as a Windows Service

nssm start Caddy

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

{
    email myemail@domain.com
 
}
 
junipermedia.net {
    
   reverse_proxy http://192.168.0.200:80
 
}
DO NOT REDACT anything except credentials

3. The problem I’m having:

My caddy file (without trying to add the log) was working fine. But now I’m trying to incorporate this example someone else is using to do the same thing, but I believe I keep messing up the Opening & Closing Brackets. Here is the example of what I’m trying to incorporate:

{
    email myemail@domain.com
 
}
 
junipermedia.net {
    
   reverse_proxy http://192.168.0.200:80

{
    encode gzip
        log {
            output file C:\caddy\logs\emby_access.log {
                roll true               # Rotate logs, enabled by default
                roll_size_mb 5          # Set max size 5 MB
                roll_gzip true          # Whether to compress rolled files
                roll_local_time true    # Use localhost time
                roll_keep 2             # Keep at most 2 log files
                roll_keep_days 7        # Keep log files for 7 days
            }

4. Error messages and/or full log output:

I keep getting an error about gzip. Should I remove gzip? Are my brackets messed up?.

5. What I already tried:

Refer to #4 above

6. Links to relevant resources:

Any help would be greatly appreciated.

Please use ``` on lines before and after your config, it preserves whitespace and makes it easier to read. I went ahead and edited your post with that change.

You’re on the right track, the brackets are the issue. Every { should have a matching } to close a block.

Please read the Caddyfile structure docs, it should explain to you what you’re doing wrong:

Thank you for your response and assistance with my Caddyfile.

I attempted to start Caddy from the Command Line (Caddy Run) and I received the following message:

2020/05/29 19:51:52.177 <-[34mINFO<-[0m using adjacent Caddyfile
run: adapting config using caddyfile: Caddyfile:20 - Error during parsing: Unexpected EOF

Any idea what’s causing this or how to resolve it? Thank you

Also, when I run my original Caddy file it works as expected:
{
email myemail@domain.com

}

junipermedia.net {

reverse_proxy http://192.168.0.200:80

{

What Francis was getting at was that you need to close your brackets. Your original file has a close bracket for every open bracket. Your new file is missing some close brackets.

1 Like

Thank you…that wasn’t clear to me, but since I’m new to Caddy, it doesn’t surprise me. I’ve reviewed the Caddyfile Concept Structure that Francis recommended, but I’m still not completely getting it.

Can someone please help me clean-up my attempt at a Caddyfile. I feel confident with the top portion down with the closing bracket after “reverse_proxy…”, but the encode & logging lines are throwing me off. I thought this “might” be right, but still getting errors “Caddyfile 14”

Any help would be appreciated.

{
    email myemail@domain.com
}
 
junipermedia.net {
    
   reverse_proxy http://192.168.0.200:80
}

        encode gzip {
        log 
            output file C:\caddy\logs\emby_access.log }
            {
                roll true               # Rotate logs, enabled by default
                roll_size_mb 5          # Set max size 5 MB
                roll_gzip true          # Whether to compress rolled files
                roll_local_time true    # Use localhost time
                roll_keep 2             # Keep at most 2 log files
                roll_keep_days 7        # Keep log files for 7 days
            }

From what I can tell this should work for you:

junipermedia.net {
  log {
        output file C:\caddy\logs\emby_access.log {
            roll_size     5MiB       # Set max size 5 MB
            roll_keep     2          # Keep at most 2 log files
            roll_keep_for 96h        # Keep log files for 4 days
        }
}
  reverse_proxy 192.168.0.200:80
}

I don’t see a roll_gzip in the log section of the documents so I left it off. Also in the docs the days for keeping logs it’s roll_keep_for and it’s in hours not days.

roll_size_mb is also labeled as roll_size in the docs and the 5 should be 5MiB. I hope that helps.

2 Likes

Thank you so very much for your assistance…greatly appreciated.

Is there an easier way to read the log files? Thanks again

I’m not exactly sure what you mean by easier to read. Do you mean to access them and read them? or are you referring to changing their layout/format?

If you want to change the format check out this link log (Caddyfile directive) — Caddy Documentation

You can change you format of the log using one of those methods.

Also check out this wiki posted not too long ago. I tried playing with jq but I’m not at that level of understanding yet.

Logs will be my next goal to get right on my system. Have fun learning Caddy!

3 Likes

Thank you again for all your help. Yes, I was referring to layout/format so the logs would be easier to read.

Thanks for sharing these resources. I will check them out and let you know what I learn.

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