From 3d08ebade02def2e148c7d78570741f43857f559 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 11 Dec 2019 22:30:33 +0100 Subject: [PATCH] Anonymize IP addresses in nginx --- templates/nginx.conf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/templates/nginx.conf b/templates/nginx.conf index 9af34bf..e687e4e 100644 --- a/templates/nginx.conf +++ b/templates/nginx.conf @@ -160,4 +160,17 @@ http { proxy_set_header Connection "upgrade"; } } + + # Anonymize IP addresses + # https://www.supertechcrew.com/anonymizing-logs-nginx-apache/ + map $remote_addr $remote_addr_anon { + ~(?P\d+\.\d+\.\d+)\. $ip.0; + ~(?P[^:]+:[^:]+): $ip::; + 127.0.0.1 $remote_addr; + ::1 $remote_addr; + default 0.0.0.0; + } + log_format main '$remote_addr_anon - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" "$http_user_agent"'; + access_log /dev/stdout main; }