Anonymize IP logging in nginx?

前端 未结 4 1079
臣服心动
臣服心动 2020-12-24 06:19

To respect the privacy of my users I\'m trying to anonymize their IP addresses in nginx log files.

One way to do this would be defining a custom log format, like so:<

4条回答
  •  鱼传尺愫
    2020-12-24 07:05

    The accepted answer seems a bit bloated. Since nginx version 1.11 it's possible to do it this way:

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

提交回复
热议问题