Varnish?


Status
Not open for further replies.

IIXPLANET

Expert 2.0
varnish memang lebih mudah diterapkan dimana2 coz ga make virtualhost misah beda dengan nginx jadi lebih mudah di aplikasikan ke beberapa tipe control panel
 

lopikunik

Beginner 2.0
Ada yang bisa bantu ga mas bro, untuk setting varnish saya, kok jika dipasang vbulletin, selalu failed untuk loginnya
 

lopikunik

Beginner 2.0
Ini versi yang udah fix.. mirip dengan script unixy tetapi tidak ada masalah dalam hal upload file..

Code:
#This is a basic VCL configuration file for varnish.  See the vcl(7)
#man page for details on VCL syntax and semantics.
#
#Default backend definition.  Set this to point to your content
#server.
#
backend default {
  .host = "_diisi dengan ip_";
  .port = "_diisi port backend_";
}

#Below is a commented-out copy of the default VCL logic.  If you
#redefine any of these subroutines, the built-in logic will be
#appended to your code.

sub vcl_recv {
    if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "TRACE" &&
      req.request != "OPTIONS" &&
      req.request != "DELETE") {
        /* Non-RFC2616 or CONNECT which is weird. */
        return (pipe);
    }
    if (req.request != "GET" && req.request != "HEAD") {
        /* We only deal with GET and HEAD by default */
        return (pass);
    }
    if (req.http.Authorization || req.http.Cookie) {
        /* Not cacheable by default */
        return (pass);
    }
    return (lookup);
}

sub vcl_fetch {

set beresp.ttl = 600s;
set beresp.http.Server = "Apache/2.2.19";

# Turn off Varnish gzip processing
set beresp.do_gzip = false;
set beresp.do_gunzip = false;
set beresp.do_stream = false;
set beresp.do_esi = false;

# Grace to allow varnish to serve content if backend is lagged
set beresp.grace = 5 m;

# Restart rule bfile for fetch
if ( beresp.http.Content-Length ~ "[0-9]{8,}" ) {
        set req.http.x-pipe = "1";
        return (restart);
}

# These status codes should always pass through and never cache.
if (beresp.status == 503 || beresp.status == 500) {
        set beresp.http.X-Cacheable = "NO: beresp.status";
        set beresp.http.X-Cacheable-status = beresp.status;
        return (hit_for_pass);
}

if (beresp.status == 404) {
        set beresp.http.magicmarker = "1";
        set beresp.http.X-Cacheable = "YES";
        set beresp.ttl = 20 s;
        return (deliver);
}

/* Remove Expires from backend, it's not long enough */
unset beresp.http.expires;

if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|pdf|ico)$" && ! (req.url ~ "\.(php)") ) 
{
        unset beresp.http.set-cookie;
        set beresp.ttl = 20 m;
}
else {
        set beresp.ttl = 5 m;
}

/* marker for vcl_deliver to reset Age: */
set beresp.http.magicmarker = "1";

# All tests passed, therefore item is cacheable
set beresp.http.X-Cacheable = "YES";

return (deliver);
}


sub vcl_deliver {

  # From http://varnish-cache.org/wiki/VCLExampleLongerCaching
  if (resp.http.magicmarker) {
     /* Remove the magic marker */
     unset resp.http.magicmarker;

     /* By definition we have a fresh object */
     set resp.http.age = "0";
   }

   #add cache hit data
   if (obj.hits > 0) {
     #if hit add hit count
     set resp.http.X-Cache = "HIT";
     set resp.http.X-Cache-Hits = obj.hits;
   }
else {
     set resp.http.X-Cache = "MISS";
   }

}

sub vcl_hit {

if (obj.ttl < 1s) {
        return (pass);
}

if (req.http.Cache-Control ~ "no-cache") {
# Ignore requests via proxy caches,  IE users and badly behaved crawlers
# like msnbot that send no-cache with every request.
if (! (req.http.Via || req.http.User-Agent ~ "bot|MSIE|HostTracker")) {
        set obj.ttl = 0s;
        return (restart);
}
}

return (deliver);

}

sub vcl_error {

if (obj.status == 503 && req.restarts < 5) {
set obj.http.X-Restarts = req.restarts;
return (restart);
}

}

sub vcl_pipe {
    set bereq.http.connection = "close";

    if (req.http.X-Forwarded-For) {
        set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
    } else {
        set bereq.http.X-Forwarded-For = regsub(client.ip, ":.*", "");
    }
}

sub vcl_pass {
    set bereq.http.connection = "close";

    if (req.http.X-Forwarded-For) {
        set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
    } else {
        set bereq.http.X-Forwarded-For = regsub(client.ip, ":.*", "");
    }
}

Hasil headernya script diatas.

Code:
HTTP/1.1 200 OK =>
Server => nginx/1.0.4
Date => Sat, 23 Jul 2011 05:07:18 GMT
Content-Type => text/html; charset=UTF-8
Connection => close
X-Pingback => http://tokohosting.biz/xmlrpc.php
X-Powered-By => W3 Total Cache/0.9.2.3
Vary => Accept-Encoding,User-Agent
X-Cacheable => YES
Content-Length => 18326
Accept-Ranges => bytes
X-Varnish => 1715052024 1715052023
Via => 1.1 varnish
age => 0
X-Cache => HIT
X-Cache-Hits => 1

Bug nya masih belum nemu lagi.. tapi upload file 3 MB udah no problem.. :) wordpress, joomla, dan cms lainnya udah jalan normal.. tidak ada kendala.. entah untuk masalah looping waktu erase thread varnishnya.. masih kejadian atau tidak..

klo settingan untuk 2 backend gmna mas bro?
ntar dibeliin cendol dah....
 

lopikunik

Beginner 2.0
apa dia listen ke port 80 atau tidak? kalau listen ya bos konfigurasi saja itu varnish mau ditaruh dimana.. di posisi tengah sebelum ke apache atau di depan sendiri..

listen port 80 Tuan, varnish mau ditaruh depan sendiri. tp permasalahnnya saya udah bikin vclnya tp klo vbulletin ditaruh diarahin dicache selalu login error failed kenapa ya itu Tuan?
 

tokohosting

Expert 1.0
listen port 80 Tuan, varnish mau ditaruh depan sendiri. tp permasalahnnya saya udah bikin vclnya tp klo vbulletin ditaruh diarahin dicache selalu login error failed kenapa ya itu Tuan?
coba aja default.vcl nya pakai ini isinya

backend default {
.host = "_diisi dengan ip_";
.port = "_diisi port backend_";
}

disave.. error apa ngga. kalau error ya mungkin tidak cocok vcl nya.. soalnya belum pernah coba di vbulletin
 

lopikunik

Beginner 2.0
coba aja default.vcl nya pakai ini isinya

backend default {
.host = "_diisi dengan ip_";
.port = "_diisi port backend_";
}

disave.. error apa ngga. kalau error ya mungkin tidak cocok vcl nya.. soalnya belum pernah coba di vbulletin
udah saya lakukan seperti Tuan untuk setting backendnya, tp vbulletinnya masih failed login.
 
Status
Not open for further replies.

Top