systeme:varnish
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
systeme:varnish [2012/11/25 10:40] – root | systeme:varnish [2014/02/15 13:41] (Version actuelle) – [Présentation] root | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
===== Présentation ===== | ===== Présentation ===== | ||
- | * [[http:// | + | Permet de limiter les requêtes pour tout ce qui est statique sur un site web. |
+ | Pour limiter le contenu dynamique avec par exemple des requêtes SQL complexes on le couplera à [[http:// | ||
===== Tuto ===== | ===== Tuto ===== | ||
* [[http:// | * [[http:// | ||
+ | * [[http:// | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | * [[https:// | ||
<note warning> | <note warning> | ||
Si le Cache-Control est à **no-cache** alors Varnish n' | Si le Cache-Control est à **no-cache** alors Varnish n' | ||
- | Pour le voir appuyer sur F12 danle navigateur Chrome : | + | Pour le voir appuyer sur F12 danle navigateur Chrome : [[http:// |
- | {{http:// | + | |
</ | </ | ||
+ | |||
+ | {{: | ||
===== Benchmark ===== | ===== Benchmark ===== | ||
* [[http:// | * [[http:// | ||
+ | |||
+ | ===== Aministration à chaud ===== | ||
+ | |||
+ | Il est possible de changer des valeurs à chaud avec l' | ||
+ | varnishadm -T localhost: | ||
+ | |||
===== Monitoring ===== | ===== Monitoring ===== | ||
Ligne 32: | Ligne 41: | ||
Pour savoir quelles requêtes sont transmises par Varnish au serveur web (Apache): | Pour savoir quelles requêtes sont transmises par Varnish au serveur web (Apache): | ||
varnishtop -i txurl | varnishtop -i txurl | ||
+ | |||
+ | Voir ce qui est demandé au serveur Apache pour **/ | ||
+ | varnishlog -b -i TxURL -I ' | ||
+ | |||
+ | ===== Script ===== | ||
+ | |||
+ | <code c> | ||
+ | # | ||
+ | sub vcl_recv { | ||
+ | # Serve objects up to 2 minutes past their expiry if the backend is slow to respond | ||
+ | set req.grace = 120s; | ||
+ | |||
+ | # Normalize encoding/ | ||
+ | if (req.http.Accept-Encoding) { | ||
+ | if (req.http.Accept-Encoding ~ " | ||
+ | elsif (req.http.Accept-Encoding ~ " | ||
+ | else { remove req.http.Accept-Encoding; | ||
+ | } | ||
+ | |||
+ | if (req.restarts == 0) { | ||
+ | if (req.http.x-forwarded-for) { | ||
+ | set req.http.X-Forwarded-For = | ||
+ | req.http.X-Forwarded-For + ", " + client.ip; | ||
+ | } else { | ||
+ | set req.http.X-Forwarded-For = client.ip; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (req.request != " | ||
+ | req.request != " | ||
+ | req.request != " | ||
+ | req.request != " | ||
+ | req.request != " | ||
+ | req.request != " | ||
+ | req.request != " | ||
+ | # Non-RFC2616 or CONNECT which is weird. | ||
+ | return (pipe); | ||
+ | } | ||
+ | |||
+ | if (req.request != " | ||
+ | # We only deal with GET and HEAD by default | ||
+ | return (pass); | ||
+ | } | ||
+ | |||
+ | # If the request is static | ||
+ | if (req.url ~ " | ||
+ | # Make the request static by removing any cookies set by those static files | ||
+ | unset req.http.cookie; | ||
+ | return (lookup); | ||
+ | } | ||
+ | |||
+ | if (req.http.Authorization || req.http.Cookie) { | ||
+ | # Not cacheable by default | ||
+ | return (pass); | ||
+ | } | ||
+ | |||
+ | return (lookup); | ||
+ | } | ||
+ | |||
+ | sub vcl_pass { | ||
+ | set req.http.X-marker = " | ||
+ | } | ||
+ | |||
+ | sub vcl_fetch { | ||
+ | set beresp.grace = 120s; | ||
+ | unset beresp.http.Server; | ||
+ | |||
+ | # Maximum 24h de cache | ||
+ | set beresp.ttl = 86400s; | ||
+ | set beresp.http.cache-control = " | ||
+ | remove beresp.http.Pragma; | ||
+ | remove beresp.http.Expires; | ||
+ | |||
+ | if (req.http.X-marker == " | ||
+ | unset req.http.X-marker; | ||
+ | set beresp.http.X-marker = " | ||
+ | #set beresp.ttl = 0s ; | ||
+ | } | ||
+ | |||
+ | # If the request is static | ||
+ | if (req.url ~ " | ||
+ | # Cache it, and make it last 24 hours | ||
+ | set beresp.ttl = 86400s; | ||
+ | # Make the request static by removing any cookies set by those static files | ||
+ | unset beresp.http.set-cookie; | ||
+ | # Deliver the cached object | ||
+ | #return (deliver); | ||
+ | } | ||
+ | |||
+ | return (deliver); | ||
+ | } | ||
+ | |||
+ | sub vcl_deliver { | ||
+ | if (obj.hits > 0){ | ||
+ | set resp.http.X-Gigix-Cache = " | ||
+ | }else{ | ||
+ | set resp.http.X-Gigix-Cache = " | ||
+ | } | ||
+ | if (resp.http.X-marker == " | ||
+ | remove resp.http.X-marker; | ||
+ | set resp.http.X-Gigix-Cache = " | ||
+ | } | ||
+ | |||
+ | remove resp.http.Via; | ||
+ | remove resp.http.X-Varnish; | ||
+ | remove resp.http.Server; | ||
+ | remove resp.http.X-Powered-By; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Apache ===== | ||
+ | |||
+ | Changer le **LogFormat** par : | ||
+ | < | ||
+ | LogFormat " | ||
+ | </ | ||
+ | |||
+ | Puis changer dans les vhosts : | ||
+ | < | ||
+ | CustomLog / | ||
+ | </ | ||
+ | |||
+ | Pour que la variable php **$_SERVER[" | ||
+ | |||
+ | < | ||
+ | sudo apt-get install libapache2-mod-rpaf | ||
+ | </ | ||
+ | |||
+ | Configurer rpaf pour un vhost : | ||
+ | < | ||
+ | < | ||
+ | RPAFenable On | ||
+ | RPAFsethostname On | ||
+ | RPAFproxy_ips 172.27.0.1 | ||
+ | RPAFheader X-Forwarded-For | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Où RPAFproxy_ips est l'ip de votre reverse-proxy. La variable RPAFproxy_ips peut prendre plusieurs IP séparées par un espace. | ||
+ | |||
+ | |||
+ | ===== Purge du cache ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | |||
+ | ===== Streaming ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | * **__A retenir :__** pour activer le streaming avec Varnish, il suffit de rajouter l’instruction set beresp.do_stream = true; dans la boucle vcl_fetch de votre configuration. La version actuelle de Varnish ne permet qu’un seul stream à la fois. Il faut utiliser la version “s”, ici 3.0.2s, pour bénéficier de la nouvelle implémentation du streaming… En attendant la prochaine release majeure. |
systeme/varnish.1353840051.txt.gz · Dernière modification : 2012/11/25 10:40 de root