The logic behind varnish is that it never touches your ruby/php code base and served directly by the cache. What if I have an ecommerce site and for each category page I want to log a particular page viewed by user/ip address X at what time, I have put this logging code in my php code. However when I run the app with Varnish then I lost all of this ability. I am pretty new to gateway proxy cache, can anyone enlighten me?
The easiest most efficient way to solve this is to create an ajax request that does just the logging part. That way you can still cache your whole page whereas you disable cache for the ajax request to enable it to log all users. The IP you would forward from varnish to the ajax request (with X-Forwarded-For), the URL you easily get with javascript and include in the ajax call (browser referral headers are not reliable).