Varnish cache - Joomla login issues - session - Joomla! Forum - community, help and support


hi,

i found fantastic guide setup varnish cache joomla. problem is not functional varnish cache configuration.

so here code:

code: select all

# place following 2 configuration blocks right after "backend default {…}" block
# inside /etc/varnish/default.vcl file (the main varnish configuration file)

# varnish configuration makes use of custom http header determin whether
# user logged in or not inside joomla! allow this, append code
#       // set user state in headers
#      if (!$user->guest) {
#         jresponse::setheader('x-logged-in', 'true', true);
#      } else {
#         jresponse::setheader('x-logged-in', 'false', true);
#      }
# on "function onafterinitialise(){ ... } function, right after "$user= jfactory::getuser();"
# in joomla! cache plugin php file located @ /plugins/system/cache/cache.php
# finally, enable plugin via joomla! backend.
# if don't want use cache plugin, add code in template's index.php file.
# don't forget prepend "$user = jfactory::getuser();"

# following setup assumes 5 min cache time - can safely drop 1 min popular/busy sites

sub vcl_recv {

    # forward client's ip backend
   remove req.http.x-forwarded-for;
   set req.http.x-forwarded-for = client.ip;

   # proxy (pass) request goes backend admin,
   # banner component links or post requests
    # can add more pages or entire url structure in end of "if"
   if(req.http.cookie ~ "userid" || req.url ~ "^/administrator" || req.url ~ "^/component/banners" || req.request == "post") {
      return (pass);
   }
   
   # check custom "x-logged-in" header identify if visitor guest,
   # unset cookie (including session cookies) provided it's not post request
   if(req.http.x-logged-in == "false" && req.request != "post"){
      unset req.http.cookie;
   }

   # handle different encoding types
   if (req.http.accept-encoding) {
     if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
       # no point in compressing these
       remove req.http.accept-encoding;
     } elsif (req.http.accept-encoding ~ "gzip") {
       set req.http.accept-encoding = "gzip";
     } elsif (req.http.accept-encoding ~ "deflate") {
       set req.http.accept-encoding = "deflate";
     } else {
       # unknown algorithm (aka crappy browser)
       remove req.http.accept-encoding;
     }
   }

   # cache files these extensions
   if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
      return (lookup);
   }

   # set how long varnish cache content depending on whether backend healthy or not
   if (req.backend.healthy) {
      set req.grace = 5m;
   } else {
      set req.grace = 1h;
   }

   return (lookup);
}

sub vcl_fetch {
   
   # check custom "x-logged-in" header identify if visitor guest,
   # unset cookie (including session cookies) provided it's not post request
   if(req.request != "post" && beresp.http.x-logged-in == "false") {
      unset beresp.http.set-cookie;
   }
   
   # allow items stale if needed (this value should same "set req.grace"
   # inside sub vcl_recv {…} block (the 2nd part of if/else statement)
   set beresp.grace = 1h;
   
   # serve pages cache should sudden error , re-check in 1 minute
   if (beresp.status == 503 || beresp.status == 502 || beresp.status == 501 || beresp.status == 500) {
     set beresp.grace = 60s;
     return (restart);
   }
   
   # unset "etag" header (suggested)
   unset beresp.http.etag;
   
   # joomla! specific: fix stupid "no-cache" header sent joomla! even
   # when caching on - make sure replace 300 number of seconds that
   # want browser cache content
   if(beresp.http.cache-control == "no-cache" || beresp.http.cache-control == ""){
      set beresp.http.cache-control = "max-age=300, public, must-revalidate";
   }
   
   # how long varnish cache content
   set beresp.ttl = 5m;
   
   return (deliver);
}


source: https://snipt.net/fevangelou/the-perfect-varnish-configuration-for-joomla-websites/

i can confirm varnish config works quite apart login.
as apply config users can't login on frontend. no login , no logout.
it seems me messes session process.

i use memcache ok, varnish overrides joomla session handling.
my question here there chance "fix" or modify varnish config , don't let varnish intervention in session process?

it big help.

thanks

hi,

looking @ configuration, can see there cookie name 'userid' defined tells whether joomla user logged in or not. however, cookie not part of joomla core, should using joomla plugin add cookie whenever login needs occur. did make sure install such plugin?

i found on jed: http://extensions.joomla.org/extensions ... ache/28387
did check extension out already?





Comments

Popular posts from this blog

Warning, the Safe Path is not accessible vm3 - Joomla! Forum - community, help and support

uppercase letters in url - Joomla! Forum - community, help and support

Joomla! Update is not offering Joomla 3 - Joomla! Forum - community, help and support