Ir para conteúdo

Featured Replies

Postado

Olá, quero saber como usar o varnish cache com vários sites e ips, meu arquivo de configuração está assim conferir abaixo:

* uso cpanel

* já correto pra cada site, mais vão tudo pra pagina default do cpanel

* como adapta esse codígo pra aceita meus segundos ips?

 

 

Citar
  1. backend default {
  2.         .host = "127.0.0.1";
  3.         .port = "8080";
  4. }
  5.  
  6. # Enable flushing access only to internals
  7. acl flushers {
  8.         "127.0.0.1";
  9. }
  10.  
  11. sub vcl_recv {
  12.         # Set backend depending on host
  13.         set req.backend = default;
  14.  
  15.         # Set a unique cache header with client ip
  16.         if (req.restarts == 0) {
  17.                 if (client.ip != "127.0.0.1") {
  18.                         if (req.http.X-Forwarded-For) {
  19.                                 set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
  20.                         } else {
  21.                                 set req.http.X-Forwarded-For = client.ip;
  22.                         }
  23.                 }
  24.         }
  25.  
  26.         # Allow the backend to deliver old content up to 1 day
  27.         set req.grace = 24h;
  28.  
  29.         # Only allow known requests
  30.         if (req.request != "GET" &&
  31.           req.request != "HEAD" &&
  32.           req.request != "PUT" &&
  33.           req.request != "POST" &&
  34.           req.request != "TRACE" &&
  35.           req.request != "OPTIONS" &&
  36.           req.request != "DELETE") {    
  37.        
  38.                 /* Non-RFC2616 or CONNECT which is weird. */
  39.                 return (pipe);
  40.         }
  41.  
  42.         # If neither GET nor HEAD request, send to backend but do not cache
  43.         # This means that POST requests are not cached
  44.         if (req.request != "GET" && req.request != "HEAD") {
  45.                 return (pass);
  46.         }
  47.  
  48.         # Strip hash as the server doesn't need it
  49.         if (req.url ~ "\#") {
  50.                 set req.url = regsub(req.url, "\#.*$", "");
  51.         }
  52.  
  53.         # Always cache the following file types for all users
  54.         if (req.url ~ "\.(png|gif|jpeg|jpg|ico|swf|css|js|pdf|txt)(\?|$)") {
  55.                 unset req.http.Cookie;
  56.         }
  57.  
  58.         # If any authorisation was set do not cache
  59.         if (req.http.Authorization || req.http.Cookie ~ "fe_typo_user") {
  60.                 return (pass);
  61.         }
  62.  
  63.         # If we work in backend don't cache anything
  64.         if (req.http.Cookie ~ "be_typo_user") {
  65.                 return (pass);
  66.         } else {
  67.                 # Pass all no_cache=1 sites and eID scripts
  68.                 if (req.url ~ "(\?|&)no_cache=1" || req.url ~ "(\?|&)eID=") {
  69.                         return (pass);
  70.                 }
  71.                 # Delete cookies
  72.                 unset req.http.Cookie;
  73.         }
  74.  
  75.         # Handle compression correctly. Different browsers send different
  76.         # "Accept-Encoding" headers, even though they mostly all support the same
  77.         # compression mechanisms.
  78.         if (req.http.Accept-Encoding) {
  79.                 if (req.http.Accept-Encoding ~ "gzip") {
  80.                         # If the browser supports gzip, that is what we use
  81.                         set req.http.Accept-Encoding = "gzip";
  82.                 } else if (req.http.Accept-Encoding ~ "deflate") {
  83.                         # Next try deflate encoding
  84.                         set req.http.Accept-Encoding = "deflate";
  85.                 } else {
  86.                         # Unknown algorithm. Remove it and send unencoded.
  87.                         unset req.http.Accept-Encoding;
  88.                 }
  89.         }
  90.  
  91.         # Lookup in cache
  92.         return (lookup);
  93. }
  94.  
  95. sub vcl_hash {
  96.         hash_data(req.url);
  97.  
  98.         if (req.http.Host) {
  99.                 hash_data(req.http.Host);
  100.         } else {
  101.                 hash_data(server.ip);
  102.         }
  103.  
  104.         return (hash);
  105. }
  106.  
  107. sub vcl_fetch {
  108.         # Set default cache to 24 hours
  109.         set beresp.ttl = 24h;
  110.  
  111.         # Deliver old content up to 1 day
  112.         set beresp.grace = 24h;
  113.  
  114.         # Set cache for 3 days
  115.         if (req.url ~ "\.(png|gif|jpeg|jpg|ico|swf|css|js|pdf|txt)(\?|$)") {
  116.                 set beresp.ttl = 72h;
  117.         }
  118.  
  119.         # Delete cookie
  120.         if (req.request == "POST" || req.url ~ "^/typo3" || req.url ~ "(\?|&)eID=") {
  121.         } else {
  122.                 unset beresp.http.Set-Cookie;
  123.         }
  124.  
  125.         if (beresp.ttl <= 0s || beresp.http.Set-Cookie || beresp.http.Vary == "*") {
  126.                 return (hit_for_pass);
  127.         }      
  128.  
  129.         # Add additional information for backend server
  130.         if (client.ip ~ flushers) {
  131.                 set beresp.http.X-TTL = beresp.ttl;
  132.                 set beresp.http.X-Grace = beresp.grace;
  133.         }
  134.  
  135.         return (deliver);
  136. }
  137.  
  138. sub vcl_deliver {
  139.         if (client.ip !~ flushers) {
  140.                 # Remove some significant headers
  141.                 unset resp.http.X-Varnish;
  142.                 unset resp.http.Via;
  143.                 unset resp.http.Age;
  144.                 unset resp.http.X-Powered-By;
  145.         } else {
  146.                 # Add additional information for backend server
  147.                 if (obj.hits > 0) {
  148.                         set resp.http.X-Cache = "Hit (" + obj.hits + ")";
  149.                 } else {
  150.                         set resp.http.X-Cache = "Miss";
  151.                 }
  152.         }
  153.  
  154.         return (deliver);
  155. }

 

Editado por Agnaldofreitas


Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.
Nota: Sua postagem exigirá aprovação do moderador antes de ficar visível.

Visitante
Infelizmente, seu conteúdo contém termos que não são permitimos. Edite seu conteúdo para remover as palavras destacadas abaixo.
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Informação Importante

Concorda com os nossos termos?