Skip to main content


I have a problem, I had to enable the error log of #Nginx and it seems there is not way to anonymize the IPs in it. What am I missing, how can I remove the IPs or shorten them by 2 octets?
#linux #help
Try this:
map $remote_addr $ip_anonymized {
 default 0.0.0.0;
}

log_format anonymized '$ip_anonymized - $remote_user [$time_local] '
   '"$request" $status $body_bytes_sent '
   '"$http_referer" "$http_user_agent"';
Then do something like:
error_log      /var/log/nginx/error.log anonymized;
@Brian Ó 🐟 did you try this for error log, it seems that most ways only work for access log. Maybe it is not possible for error logs?
When I do this I put the first bit in a file in /etc/nginx/conf.d and then refer to it in my vhost configs.
Why is it needed though? IPs can be helpful when diagnosing problems and error log is not supposed to be anywhere public anyway.
@Alexander almost never needed the ip to diagnose, two starting or ending octets are OK for me, as there is only a few dozen lines per minute in the error log. Storing personal data should be avoided whenever possible.
schau mal hier, sollte mit einem custom logging format gehen: https://docs.nginx.com/nginx/admin-guide/monitoring/logging/
I generally use it for access, yeah, but I assume it would work for error too. You may have to adjust the formatting.