améliorations
This commit is contained in:
parent
833bff1f38
commit
d47f3ef492
|
@ -33,15 +33,17 @@ Copyright (c) 2006-2014 Varnish Software AS
|
|||
`/etc/systemd/system/varnish.service` :
|
||||
|
||||
~~~
|
||||
ExecStart=/usr/sbin/varnishd -a 0.0.0.0:80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,2G -p thread_pools=<Nombre de cores CPU> -p thread_pool_add_delay=2 -p thread_pool_min=500 -p thread_pool_max=5000
|
||||
ExecStart=/usr/sbin/varnishd -a 0.0.0.0:80 -T localhost:6082 -f /etc/varnish/default.vcl \
|
||||
-S /etc/varnish/secret -s malloc,2G \
|
||||
-p thread_pools=<Nombre de cores CPU> -p thread_pool_add_delay=2 -p thread_pool_min=500 -p thread_pool_max=5000
|
||||
~~~
|
||||
|
||||
Détails de certaines options :
|
||||
|
||||
* `-a` : spécifie *IP*:*port* sur lequel Varnish écoute pour les requêtes HTTP. On peut ainsi spécifier une IP secondaire pour cœxister avec un autre service HTTP (Apache, Nginx) sur le port 80 (*-a 192.0.2.1:80*) ou faire écouter Varnish uniquement en local (*-a 127.0.0.1:8080*) ou alors le faire écouter de partout (*-a 0.0.0.0:80*) ou même spécifier plusieurs IP (*-a 0.0.0.0:80,127.0.0.1:81*)
|
||||
* `-s` : spécifie où est stocké le cache. Cela peut être en mémoire (*-s malloc,2G*) et/ou dans un fichier (*-s file,varnish_storage.bin,8G*)
|
||||
* `-T` : spécifie l'interface d'admin web de Varnish
|
||||
* `-f` : spécifie le fichier des règles Varnish au format VCL (*Varnish Configuration Language*)
|
||||
* `-s` : spécifie où est stocké le cache. Cela peut être en mémoire (*-s malloc,2G*) et/ou dans un fichier (*-s file,varnish_storage.bin,8G*)
|
||||
|
||||
Note 1 : le fichier */etc/default/varnish* [n'est malheureusement plus utilisé avec Systemd](https://bugs.debian.org/749272)
|
||||
|
||||
|
@ -285,8 +287,6 @@ if (req.http.x-forwarded-for)
|
|||
if (req.http.Authorization || req.http.Cookie)
|
||||
# Condition
|
||||
if (req.http.Cache-Control ~ "no-cache")
|
||||
# Si la réponse du backend permet la mise en cache
|
||||
if (beresp.cacheable)
|
||||
# Condition sur le temps de mise (Cache-Control: max-age a priori)
|
||||
if (beresp.ttl < 120s)
|
||||
# Condition sur le statut des réponses
|
||||
|
@ -367,21 +367,22 @@ sub vcl_recv {
|
|||
sub vcl_backend_response {
|
||||
if (beresp.status == 403 || beresp.status == 404 || beresp.status == 503 || beresp.status == 500) {
|
||||
set beresp.ttl = 10s;
|
||||
set beresp.cacheable = true;
|
||||
}
|
||||
if (!obj.cacheable) {
|
||||
set obj.http.X-Cacheable = "NO";
|
||||
return (pass);
|
||||
}
|
||||
|
||||
if (beresp.uncacheable) {
|
||||
set beresp.http.X-Cacheable = "FALSE";
|
||||
} else {
|
||||
set beresp.http.X-Cacheable = "TRUE";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub vcl_deliver {
|
||||
if (obj.hits > 0) {
|
||||
set resp.http.X-Cache = "HIT";
|
||||
set resp.http.X-Cache-Hits = obj.hits;
|
||||
} else {
|
||||
set resp.http.X-Cache = "MISS";
|
||||
}
|
||||
if (resp.http.X-Varnish ~ "[0-9]+ +[0-9]+") {
|
||||
set resp.http.X-Cache = "HIT";
|
||||
} else {
|
||||
set resp.http.X-Cache = "MISS";
|
||||
}
|
||||
}
|
||||
~~~
|
||||
|
||||
|
|
Loading…
Reference in a new issue