Central anonymized IP addresses for nginx for all virtual hosts

January 2, 2015

In germany you need to anonymize ip address where ever you work with such data. This also applies for webserver logs, such as nginx.

We just need to rewrite the value of $remote_ip into something like $ip_anonymized.

But this is not as easy as it sounds at first glance (and also already provided solutions on stackoverflow do not properly work).

Let’s have a look, what we have:

nginx has the log_format directive, which has a context of http. This means, the log_format can only be (valid) set within the http {} section of the config file, NOT within the server sections!

On the other hand we have an if directive, which has a context of server and location.

So we can NOT use “if” and “log_format” on a central place, since the if part we would need to put on each virtual server entry.

But I like to have a central managed rewrite of the $remote_ip. So the if is not helpful here, also if is evil! We need something which is working at http context because only there the log_format can be defined in a valid way, and this is the only place outside of the server context, where our virtual hosts are defined…

Luckily there is a map feature within nginx! map is remapping some values into new values (accessible within variables which can be used in a log_format directive). And the good message: This also works with regular expressions.

So let’s map our IPv4 and IPv6 addresses into anonymized addresses. This has to be done in 3 steps, since map can not accumulate returned values, it can only return strings or variables, not a combination of both.

So, at first I grab the part of IP I want to have in my logfiles, the second map returns the part which symbolizes the anonymized part, and the 3rd map rule maps them together again.


Here are the rules which go into the http {} context:

map $remote_addr $ip_anonym1 {
 default 0.0.0;

 "~(?P<ip>(\d+)\.(\d+)\.(\d+))\.\d+" $ip;
 "~(?P<ip>[^:]+:[^:]+):" $ip;
map $remote_addr $ip_anonym2 {
 default .0;
 "~(?P<ip>(\d+)\.(\d+)\.(\d+))\.\d+" .0;
 "~(?P<ip>[^:]+:[^:]+):" ::;
map $ip_anonym1$ip_anonym2 $ip_anonymized {
 "~(?P<ip>.*)" $ip;
log_format anonymized '$ip_anonymized - $remote_user [$time_local] ' 
   '"$request" $status $body_bytes_sent ' 
   '"$http_referer" "$http_user_agent"';
 access_log /var/log/nginx/access.log anonymized;

After adding this to your nginx.conf config file, remember to reload your nginx. Your log files should now contain anoymized IP addresses, if you are using the “anonymized” log format (this is the format parameter of access_log directive).


Comments Off

How to record a video of your iPhone Applications

July 13, 2011

Today I was looking for a solution, how to record a video right on my desk using the iOS Simulator. I like to show people in a short movie, how to use an app or just what the app is all about.
After a short google I found a post on Ed’s Blog where 2 Software packages are mentioned. First SIMBL and second iPhone Simulator Capture. I downloaded and installed both packages (they ship as PKG installables) and them started iOS Simulator. NO additional setup was needed.

Suddenly there is a “Recording” menu in the iOS Simulator. I found it useful to enable mouse pointer recording … anyway, after 2 minutes searching and installing I was able to record my actions in the simulator :) Cool stuff.. I’ll show a video shortly, I guess.

Comments Off

IVAO – Into the Sky

July 13, 2011
Tags: , , ,

Here it is, my latest released project, this time without a commercial background, just for fun.

IVAO stands for “International Virtual Aviation Organization” and as such IVAO provides a network (webserver, gaming servers and additional software packages) which enables FlightSimulator enthusiasts to fly online with others, to have “real” Air Traffic Control, gain achievements or just have fun.

Since some months (or years?) there were plenty requests rising up in the community to have a tool für iOS devices (read: iphone), but surprisingly nobody made it. As I read about the discussions in the forums, I decided to have a try on it. So I sent a request to the IVAO network department to gain the permission to access the network data. Then – some weeks went by. And I almost forgot about the request, since other projects needed my attention.

One day, the approval came right from the network staff, and I was surprised to get a reaction that late. But it was the start point for the project, again.

You can check the initial version of my new product “IVAO – Into the Sky” in the AppStore
since yesterday. “Into the Sky” displays the current activity on the IVAO network around the world. You can list pilots, ATC and observers, you can search or even see on a map where they all are flying (or standing on ground ;).

A lot more features are already planned including iPad support, member profiles, friends, scheduling etc.

If you like the app, please leave a review in the App Store, on Facebook or in the IVAO Forum.
Comments Off

FBinsights – Price Drop for 3 days

June 30, 2011

From July 1st to July 3rd there is a 50% discount on FBinsights full version. Let’s celebrate my 39th birthday :)

Comments Off

New facebook-ios-sdk: Howto build an “old style” within-the-app login dialog

January 10, 2011

With the new facebook-ios-sdk we have got a “single sign on” feature. The good thing is, that this really sounds nice and handy. The bad thing is, that sometimes this SSO simply does not work. Some users have trouble to find the “OK” button to continue the login process. Also your application has to have multitasking abilities.

Well, I really do not like it if my app users can not use my app because facebook login masks are not working. So, I prefer to enable my users to disable the SSO (within the app settings) and popup the facebook login dialog myself.

Here is the code you need:

Facebook *fb = [[Facebook alloc] initWithAppId:FB_APP_ID];
self.facebook = fb;
[fb release];
// Setting the sessionDelegate is important for current SDK version,
// otherwise fbDidLogin or fbDidNotLogin is not called.
self.facebook.sessionDelegate = self;

// Define some dialog params
NSMutableDictionary *params =
  [NSMutableDictionary dictionaryWithCapacity:10];

[params setObject:FB_APP_ID forKey:@"client_id"];
[params setObject:@"publish_stream" forKey:@"scope"]

// Now popup the login dialog
[self.facebook dialog:@"oauth" andParams:params andDelegate:self]


Details for dialog parameters you can find on facebook dialog documentation page: http://developers.facebook.com/docs/reference/dialogs/oauth

If you find this code snipped useful, please share it.


Newest Product: FBinsights for iPhone

January 15, 2009

FBinsights Splash ScreenFBinsights Sample OverviewMy latest project is an application for iPhone / iPod / iPad: FBinsights.

You can use FBinsights to display your facebook page and application analytics (“insights”) in your device. FBinsights is available in the app store.