Skip to content

Commit

Permalink
nginx: anonymize ip addresses in log files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreddow committed Jan 2, 2025
1 parent 4351ba9 commit ded0e05
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docker/nginx/config/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@
upstream host_service {
server backend:8081;
}

map $remote_addr $remote_addr_anon {
~(?P<ip>\d+\.\d+\.\d+)\. $ip.0;
~(?P<ip>[^:]+:[^:]+): $ip::;
127.0.0.1 $remote_addr;
::1 $remote_addr;
default 0.0.0.0;
}

log_format anon '$remote_addr_anon - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

server {
listen 80 default_server;

server_name my.warp-charger.com;

access_log /var/log/nginx/access.log anon;

return 301 https://$host$request_uri;
}

Expand Down Expand Up @@ -58,4 +73,6 @@ server {
proxy_http_version 1.1;
proxy_set_header Connection "";
}

access_log /var/log/nginx/access.log anon;
}
17 changes: 17 additions & 0 deletions docker/nginx/dev-config/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
upstream host_service {
server 172.17.0.1:8081;
}

map $remote_addr $remote_addr_anon {
~(?P<ip>\d+\.\d+\.\d+)\. $ip.0;
~(?P<ip>[^:]+:[^:]+): $ip::;
127.0.0.1 $remote_addr;
::1 $remote_addr;
default 0.0.0.0;
}

log_format anon '$remote_addr_anon - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

server {
listen 80 default_server;

Expand Down Expand Up @@ -45,6 +58,8 @@ server {
proxy_http_version 1.1;
proxy_set_header Connection "";
}

access_log /var/log/nginx/access.log anon;
}

server {
Expand Down Expand Up @@ -96,4 +111,6 @@ server {
proxy_http_version 1.1;
proxy_set_header Connection "";
}

access_log /var/log/nginx/access.log anon;
}

0 comments on commit ded0e05

Please sign in to comment.