Varnish Cache
  • Varnish Cache
  • Varnish Cache Nedir?
    • Varnish Cache
    • Varnish Açık Kaynak Bir Proje
    • Varnish Nasıl Çalışır?
  • Varnish Başlangıç
    • Varnish Kurulumu
      • Paket Yöneticisi Kullanarak Varnish Kurulumu
      • Ubuntu ve Debian Üzerinde Varnish Kurulumu
      • Red Hat and CentOS Üzerinde Varnish Kurulumu
    • Varnish Yapılandırma
      • Yapılandırma Dosyası
      • Ubuntu ve Debian için Systemd Ek Bilgi
      • Başlangıç Seçenekleri
    • TLS/SSL Hakkında
  • Varnish HTTP
    • Varnish ve HTTP
    • Idempotence
    • State (Durum)
    • Expiration (Süre sonu)
      • Expires Header
      • Cache-Control Header
      • Expiration Precedence (Bitiş Süresi Önceliği)
    • Koşullu İstekler
      • ETag
      • Last-Modifed
      • Koşullu İstekler ile Varnish İşlemleri Nasıl Yapılır?
    • Önbellek Varyasyonları
    • Varnish Hakkında Bazı Sorular
  • Varnish Yapılandırma Dili (VCL)
    • Varnish Yapılandırma Dili (VCL)
    • Kancalar ve Alt Yordamlar
      • İstemci Tarafı Alt Yordamları
      • Arka Uç Alt Yordamları
      • Başlatma ve Temizleme Alt Yordamlar
      • Özel Alt Rutinler
    • Dönüş İfadeleri
    • Akış Şeması
    • VCL Sintaks
      • Operatörler
      • Koşullar
      • Yorumlar
      • Değerler
      • Düzenli İfadeler
      • Include
      • Varnish Modüllerini Dahil Etme
    • Arka Uçlar (Backends) ve Health Probes
    • Erişim Kontrol Listeleri (ACL)
    • VCL Değişkenleri
    • Varnish'in Dahili VCL'i
  • Önbelleği Geçersiz Kılma
    • Purging
    • Banning
      • Lurker-Friendly Bans
      • Ban Listesi
    • Zorla Önbelleği Geçersiz Kılmak
  • Backend Kullanımı
    • Backend Kullanımı
    • Backend Seçimi
    • Backend Sağlığı
    • Directors
      • Round-Robin Director
      • Random Director
      • Hash Director
      • Fallback Director
    • Grace Mode
      • Grace Mode Aktif Et
  • Loglama ve Debug
    • Loglama ve Debug
    • Varnishstat
    • Varnishtop
  • Varnish Modüller
    • Varnish Modüller
    • libvmod-geoip
    • libvmod-vsthrottle
  • Kaynaklar
    • Kaynaklar
Powered by GitBook
On this page

Was this helpful?

  1. Varnish Yapılandırma Dili (VCL)

Varnish'in Dahili VCL'i

default.vcl
vcl 4.0;

#######################################################################
# Client side

sub vcl_recv {
    if (req.method == "PRI") {
	/* We do not support SPDY or HTTP/2.0 */
	return (synth(405));
    }
    if (req.method != "GET" &&
      req.method != "HEAD" &&
      req.method != "PUT" &&
      req.method != "POST" &&
      req.method != "TRACE" &&
      req.method != "OPTIONS" &&
      req.method != "DELETE" &&
      req.method != "PATCH") {
        /* Non-RFC2616 or CONNECT which is weird. */
        return (pipe);
    }

    if (req.method != "GET" && req.method != "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 (hash);
}

sub vcl_pipe {
    # By default Connection: close is set on all piped requests, to stop
    # connection reuse from sending future requests directly to the
    # (potentially) wrong backend. If you do want this to happen, you can undo
    # it here.
    # unset bereq.http.connection;
    return (pipe);
}

sub vcl_pass {
    return (fetch);
}

sub vcl_hash {
    hash_data(req.url);
    if (req.http.host) {
        hash_data(req.http.host);
    } else {
        hash_data(server.ip);
    }
    return (lookup);
}

sub vcl_purge {
    return (synth(200, "Purged"));
}

sub vcl_hit {
    if (obj.ttl >= 0s) {
        // A pure unadultered hit, deliver it
        return (deliver);
    }
    if (obj.ttl + obj.grace > 0s) {
        // Object is in grace, deliver it
        // Automatically triggers a background fetch
        return (deliver);
    }
    // fetch & deliver once we get the result
    return (miss);
}

sub vcl_miss {
    return (fetch);
}

sub vcl_deliver {
    return (deliver);
}

/*
 * We can come here "invisibly" with the following errors: 500 & 503
 */
sub vcl_synth {
    set resp.http.Content-Type = "text/html; charset=utf-8";
    set resp.http.Retry-After = "5";
    set resp.body = {"<!DOCTYPE html>
<html>
  <head>
    <title>"} + resp.status + " " + resp.reason + {"</title>
  </head>
  <body>
    <h1>Error "} + resp.status + " " + resp.reason + {"</h1>
    <p>"} + resp.reason + {"</p>
    <h3>Guru Meditation:</h3>
    <p>XID: "} + req.xid + {"</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>
"};
    return (deliver);
}

#######################################################################
# Backend Fetch

sub vcl_backend_fetch {
    if (bereq.method == "GET") {
        unset bereq.body;
    }
    return (fetch);
}

sub vcl_backend_response {
    if (bereq.uncacheable) {
        return (deliver);
    } else if (beresp.ttl <= 0s ||
      beresp.http.Set-Cookie ||
      beresp.http.Surrogate-control ~ "no-store" ||
      (!beresp.http.Surrogate-Control &&
        beresp.http.Cache-Control ~ "no-cache|no-store|private") ||
      beresp.http.Vary == "*") {
        # Mark as "Hit-For-Pass" for the next 2 minutes
        set beresp.ttl = 120s;
        set beresp.uncacheable = true;
    }
    return (deliver);
}

sub vcl_backend_error {
    set beresp.http.Content-Type = "text/html; charset=utf-8";
    set beresp.http.Retry-After = "5";
    set beresp.body = {"<!DOCTYPE html>
<html>
  <head>
    <title>"} + beresp.status + " " + beresp.reason + {"</title>
  </head>
  <body>
    <h1>Error "} + beresp.status + " " + beresp.reason + {"</h1>
    <p>"} + beresp.reason + {"</p>
    <h3>Guru Meditation:</h3>
    <p>XID: "} + bereq.xid + {"</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>
"};
    return (deliver);
}

#######################################################################
# Housekeeping

sub vcl_init {
}

sub vcl_fini {
    return (ok);
}
PreviousVCL DeğişkenleriNextPurging

Last updated 6 years ago

Was this helpful?