From b2a30145cbe11d2997d4b752ab9118ff581ae954 Mon Sep 17 00:00:00 2001 From: sfinke0 Date: Fri, 24 Feb 2023 09:46:49 +0100 Subject: [PATCH] Implement additional log format: json access logs --- Dockerfile | 3 ++- overlay/etc/nginx/conf.d/10_log_format.conf | 2 +- overlay/etc/nginx/sites-available/10_cache.conf | 2 +- overlay/etc/nginx/sites-available/20_upstream.conf | 2 +- overlay/hooks/entrypoint-pre.d/10_setup.sh | 2 ++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ad1557..54a6495 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,8 @@ ENV GENERICCACHE_VERSION=2 \ LOGFILE_RETENTION=3560 \ CACHE_DOMAINS_REPO="https://github.com/uklans/cache-domains.git" \ CACHE_DOMAINS_BRANCH=master \ - NGINX_WORKER_PROCESSES=auto + NGINX_WORKER_PROCESSES=auto \ + NGINX_LOG_FORMAT=cachelog COPY overlay/ / diff --git a/overlay/etc/nginx/conf.d/10_log_format.conf b/overlay/etc/nginx/conf.d/10_log_format.conf index 60c5b11..cb386ab 100644 --- a/overlay/etc/nginx/conf.d/10_log_format.conf +++ b/overlay/etc/nginx/conf.d/10_log_format.conf @@ -1,2 +1,2 @@ log_format cachelog '[$cacheidentifier] $remote_addr / $http_x_forwarded_for - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$upstream_cache_status" "$host" "$http_range"'; - + log_format cachelog-json escape=json '{"timestamp":"$msec","time_local":"$time_local","cache_identifier":"$cacheidentifier","remote_addr":"$remote_addr","forwarded_for":"$http_x_forwarded_for","remote_user":"$remote_user","status":"$status","bytes_sent":$body_bytes_sent,"referer":"$http_referer","user_agent":"$http_user_agent","upstream_cache_status":"$upstream_cache_status","host":"$host","http_range":"$http_range","method":"$request_method","path":"$request_uri","proto":"$server_protocol","scheme":"$scheme"}'; diff --git a/overlay/etc/nginx/sites-available/10_cache.conf b/overlay/etc/nginx/sites-available/10_cache.conf index 34cdf93..54ad6ed 100644 --- a/overlay/etc/nginx/sites-available/10_cache.conf +++ b/overlay/etc/nginx/sites-available/10_cache.conf @@ -3,7 +3,7 @@ server { listen 80 reuseport; - access_log /data/logs/access.log cachelog; + access_log /data/logs/access.log LOG_FORMAT; error_log /data/logs/error.log; include /etc/nginx/sites-available/cache.conf.d/*.conf; diff --git a/overlay/etc/nginx/sites-available/20_upstream.conf b/overlay/etc/nginx/sites-available/20_upstream.conf index 6617943..305005b 100644 --- a/overlay/etc/nginx/sites-available/20_upstream.conf +++ b/overlay/etc/nginx/sites-available/20_upstream.conf @@ -10,7 +10,7 @@ server { # No access_log tracking as all requests to this instance are already logged through monolithic - # access_log /data/logs/upstream-access.log cachelog; + # access_log /data/logs/upstream-access.log LOG_FORMAT; error_log /data/logs/upstream-error.log; include /etc/nginx/sites-available/upstream.conf.d/*.conf; diff --git a/overlay/hooks/entrypoint-pre.d/10_setup.sh b/overlay/hooks/entrypoint-pre.d/10_setup.sh index 305c96c..894b49f 100644 --- a/overlay/hooks/entrypoint-pre.d/10_setup.sh +++ b/overlay/hooks/entrypoint-pre.d/10_setup.sh @@ -19,3 +19,5 @@ sed -i "s/slice 1m;/slice ${CACHE_SLICE_SIZE};/" /etc/nginx/sites-available/cach sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/cache.conf.d/10_root.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf.d/10_resolver.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf +sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/10_cache.conf +sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/20_upstream.conf