# Anonymize IP logging

**URL:** <https://www.ruby-forum.com/t/anonymize-ip-logging/219442>\
**Category:** NGINX\
**Created:** [May 3, 2012, 6:55am UTC](https://www.ruby-forum.com/t/anonymize-ip-logging/219442 "2012-05-03T06:55:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 3, 2012, 6:55am UTC](https://www.ruby-forum.com/t/anonymize-ip-logging/219442/1 "2012-05-03T06:55:46Z")

</div>

Hello,

i’m searching for an way to anonymize the ip address in the logfiles  
of nginx. I already changed the ip to “127.0.0.1”, but then i can’t  
check for unique visitors.  
There is a mond\_anonstats modul available for apache, the same ip hash  
would be really nice for nginx.

Thanks

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [May 3, 2012, 7:57am UTC](https://www.ruby-forum.com/t/anonymize-ip-logging/219442/2 "2012-05-03T07:57:35Z")

</div>

Hello

I’m not sure if its performance wise, but you can always define your own  
log format [Module ngx\_http\_log\_module](http://wiki.nginx.org/HttpLogModule#log_format) with a custom  
variable instead of $remote\_addr which can be almost anything, try using  
for example [Lua | NGINX](http://wiki.nginx.org/HttpLuaModule) ngx.md5 or any lua code  
😉

Regards

M

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [May 3, 2012, 12:50pm UTC](https://www.ruby-forum.com/t/anonymize-ip-logging/219442/3 "2012-05-03T12:50:20Z")

</div>

> I’m not sure if its performance wise, but you can always define your own  
> log format [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpLogModule#log_format) with a custom  
> variable instead of $remote\_addr which can be almost anything, try using  
> for example [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpLuaModule) ngx.md5 or any lua code 😉

Or perl code, which is even easier, than lua 🙂

```
perl_set $anon_addr ' sub {
    use Digest::MD5 qw(md5_hex);
    my $r = shift;
    md5_hex $r->remote_addr
} ';

```

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [May 4, 2012, 6:30am UTC](https://www.ruby-forum.com/t/anonymize-ip-logging/219442/4 "2012-05-04T06:30:15Z")

</div>

2012/5/3 Alexandr G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Or perl code, which is even easier, than lua 🙂
> 
> perl\_set $anon\_addr ’ sub {  
> use Digest::MD5 qw(md5\_hex);  
> my $r = shift;  
> md5\_hex $r-\>remote\_addr  
> } ';

Thanks for the info. Is there a way to configure this globally for all  
vhosts?

I have already this lines in my nginx.conf:  
log\_format combined\_noip '127.0.0.1 - $remote\_user [$time\_local]  
’  
'“$request” $status $body\_bytes\_sent  
’  
‘“$http\_referer”  
“$http\_user\_agent”’;

So i would need the $anon\_addr instead of the 127.0.0.1.

Thanks
