From 0e9e602bb952f465e56f3483acd956714e0a082f Mon Sep 17 00:00:00 2001 From: fliespl Date: Sat, 28 Sep 2024 22:22:41 +0200 Subject: [PATCH 1/2] switch to client_ip instead of remote_ip Handles cases with load balancers when caddy already verified source (i.e. cloudflare) --- formatencoder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formatencoder.go b/formatencoder.go index 02c82ca..50b2161 100644 --- a/formatencoder.go +++ b/formatencoder.go @@ -33,7 +33,7 @@ func init() { const ( // commonLogFormat is the common log format. https://en.wikipedia.org/wiki/Common_Log_Format commonLogEmptyValue = "-" - commonLogFormat = `{request>remote_ip} ` + commonLogEmptyValue + ` {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size}` + commonLogFormat = `{request>client_ip} ` + commonLogEmptyValue + ` {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size}` commonLogTimeFormat = "02/Jan/2006:15:04:05 -0700" commonLogFormatShortcut = `{common_log}` From eba3ea1421b42be262a6d5797698d9eb0820dd75 Mon Sep 17 00:00:00 2001 From: fliespl Date: Sat, 28 Sep 2024 22:25:16 +0200 Subject: [PATCH 2/2] Update README.md with client_ip --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 25daef5..6d76eba 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The module comes with one special value of `{common_log}` for the Apache Common The more spelled out way of doing it is: ```caddyfile -format transform `{request>remote_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size}` { +format transform `{request>client_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size}` { time_format "02/Jan/2006:15:04:05 -0700" } ``` @@ -65,7 +65,7 @@ format transform `{request>remote_ip} - {user_id} [{ts}] "{request>method} {requ The more spelled out way of doing it is: ```caddy -format transform `{request>remote_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size} "{request>headers>Referer>[0]}" "{request>headers>User-Agent>[0]}"` { +format transform `{request>client_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size} "{request>headers>Referer>[0]}" "{request>headers>User-Agent>[0]}"` { time_format "02/Jan/2006:15:04:05 -0700" } ```