Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am looking to use varnish to help keep load of my web server. However I have a little problem.

The web site uses some custom tracking info which takes information like the IP, Referrer, campaign details and puts it in a cookie.

The obvious solution for this is to not cache requests that don't contain this cookie.

However this will mean that a lot of requests will not get served cached pages, including spambots and crawlers.

Can varnish set this information in a cookie it self, so that we can keep serving a cached page while setting a tracking cookie? Are there any libraries to do this?

Things to note

  • We want to use this information to identify individual people further down the line, after a conversion which is against Google analytics TOS so we can't use that.
  • a JS library by itself can't get the IP address, but if we could use a library in conjunction with a vcl rule that would be ok.
share|improve this question
    
Do you still need a solution here? –  Jens Bradler Sep 25 '13 at 22:38
    
I solved with using a js request to a tracking page which isn't ideal, if you have a vcl solution that would be very interesting. –  Jeremy French Sep 27 '13 at 12:14

1 Answer 1

You are right, JavaScript isn't able to detect the clients IP address. Additionally it doesn't make sense to put the IP in the content as this requires ESI or even make the content non-cacheable. Try to set a specific header with the client's IP address in Varnish and parse it with JavaScript:

Varnish:

sub vcl_deliver {
  ...
  set resp.http.X-Client-IP = client.ip;
  ...
  return (deliver);
}

I haven't tested it but it seem to be a good solution and you will keep the content cacheable and your site fast.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.