varnish cookies issues -


first of all, sorry poor english it's not natural language.

i try configure varnish cookies managment users backend, , have issues loggin , other checks.

my config recv, fetch , hash:

backend default {   .host = "127.0.0.1";   .port = "8080"; }  sub vcl_recv {     remove req.http.x-forwarded-for;    set req.http.x-forwarded-for = client.ip;     if (req.request == "post"){         return (pass);    }     # grace mode    if (! req.backend.healthy) {           set req.grace = 30m;    } else {       set req.grace = 15s;    }     if(req.url ~ "^localhost$"){     set req.http.host = "www.micasa.com";    }      # acces system url's protected    if ((req.url ~ "^/server_status") || (req.url ~ "^/discover/varnish_server")) {         error 403 "go away, please";    }    # delete cookies except user    if ( !(req.url ~ "^/logout") &&         !(req.url ~ "^/profile") &&         !(req.url ~ "^/playlists") &&         !(req.url ~ "^/users") &&         !(req.url ~ "^/signup") &&         !(req.url ~ "^/comments") &&         !(req.url ~ "^/login") &&         !(req.url ~ "^/remind"))         {                 unset req.http.cookie;         }  sub vcl_fetch {    # grace mode   # https://www.varnish-cache.org/docs/trunk/tutorial/handling_misbehaving_servers.html#grace-mode   set beresp.grace = 30m;    # saint mode   # https://www.varnish-cache.org/docs/trunk/tutorial/handling_misbehaving_servers.html#saint-mode   if (beresp.status == 500) {     set beresp.saintmode = 10s;     return (restart);   }   if ( !(req.url ~ "^/login") && (req.request == "get")){         unset beresp.http.set-cookie; # avoid caching of cookies   }    # process esis if x-run-esi set. stripped before being sent down client.   if ( beresp.http.x-run-esi ) {     set beresp.do_esi = true;     remove beresp.http.x-run-esi;   }    # cache 404s , 301s 5 minute   if (beresp.status == 404 || beresp.status == 301 || beresp.status == 500) {      set beresp.ttl = 15m;      return (deliver);   }    # cache images , static assets during 15m   if ( req.url ~ "\.(png|gif|jpg|css|js|ico)" ) {      set beresp.ttl = 15m;      return (deliver);   }     # if x-varnish-ttl set, use header's value ttl varnish cache.   # expires, cache-control, etc. passed directly through client   # cribbed http://www.lovelysystems.com/configuring-varnish-to-use-custom-http-headers/   if (beresp.http.x-varnish-ttl) {     c{       char *ttl;       /* first char in third param length of header plus colon in octal */       ttl = vrt_gethdr(sp, hdr_beresp, "\016x-varnish-ttl:");       vrt_l_beresp_ttl(sp, atoi(ttl));     }c     remove beresp.http.x-varnish-ttl;     return (deliver);   } sub vcl_deliver {     unset resp.http.x-url; # optional     if ( req.url ~ "\.(png|gif|jpg|css|js|ico|woff)" ) {       set resp.http.expires = "3600";     }      #mikel     #remove resp.http.x-powered-by;     remove resp.http.server;     #remove resp.http.x-varnish;     #remove resp.http.via;     #remove resp.http.age;  }  sub vcl_hash {    if (req.http.cookie ~ "_micasa_session") {      hash_data(req.url);      hash_data(req.http.cookie);          return (hash);    } } 

when try loggin user it's ok, if refresh same page after that, lose cookie , immediatly logout, maybe problem in sub vcl_recv?

thank's advance help.

you unset cookies except on defined pages. site login held in cookie (session cookie?). easy way out disable cache logged in users checking if cookie identifying logged in user set. way use esi sections same users gets cached.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -