The scenario you described is hardly possible "as is". Problems:
- Nginx cannot read cookie from memcached, as far as I know. It can pass response body only.
- Nginx can indeed call "post_action", but this functionality is in beta and you'd better avoid it.
Frankly, I don't completely understand what cookie are you going to write into memcached before the actual requst.. probably you need to give more details.
However, Nginx does many things well very which could be of use for you, so I shall outline some of them
Nginx can return an empty GIF, it's built in:
location /tracking {
empty_gif;
}
Nginx writes log very effectively, you can easily define format and write query arguments, request and response headers to the log:
log_format tracking '$remote_addr "$request" "$http_referer" $arg_param $upstream_x_track_id';
location /tracking {
access_log /var/log/tracking.log tracking buffer=16k;
proxy_pass http://upstream;
}
Since you are going to use memcached, you probably wanted to cache responses and this is what Nginx can do for you (I shall show an example with proxy, but it's possible with FastCGI as well):
proxy_cache_path /var/cache/nginx/cache_tracking keys_zone=tracking:20m;
location /tracking {
access_log /var/log/tracking.log tracking buffer=16k;
proxy_cache tracking;
proxy_cache_valid 200 1m; # Cache responses with code 200 for 1 minute
proxy_pass http://upstream;
}
You can define your own cache key and do not pass it to a client:
location /tracking {
access_log /var/log/tracking.log tracking buffer=16k;
proxy_cache_key $upstream_x_track_id;
proxy_cache tracking;
proxy_cache_valid 200 1m; # Cache responses with code 200 for 1 minute
proxy_hide_header X-Track_Id;
proxy_pass http://upstream;
}