0

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?

adit
  • 32,574
  • 72
  • 229
  • 373

3 Answers3

0

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).

Clarence
  • 2,944
  • 18
  • 16
0

A rather simple thing is to write a script to parse varnish logs, and retrieve pages of interests, ips and other interesting informations. It can be run once a day or more frequently, depends on your needs.

By using ajax request as in @Clarence response you risk to do not include the visitors with javascript not activated (but you can have your stats in real time)

ts.
  • 10,510
  • 7
  • 47
  • 73
  • You can have your stats in realtime by analyzing streamed varnishlog/varnishncsa output as well. This is a good solution to replace web server logs but is a complicated and less flexible approach when replacing a custom logging script. Any processing of the logs would need to be completely rewritten and the possibility to log custom properties related to the content is gone. – Clarence Mar 06 '15 at 11:05
0

You can add some logic to Varnish to forward IP address, so you could have complete webserver logs of client IP & requested URL.

This example is for apache: Varnish Client IP not logging in Apache Logs

[Edit] The above suggestion only works for cache misses. Client side JS recommended.

You could also consider using javascript to poll servers with information, such as Google Analytics. http://www.google.com/analytics/

Community
  • 1
  • 1
webbo
  • 339
  • 2
  • 6