Mephivio Posted May 30, 2014 Share Posted May 30, 2014 Bonjour la communauté Prestashop, Je vous propose d'ouvrir un fil à propos de Varnish 4.0 qui est disponible depuis 1 mois. Je l'utilise avec des sites Wordpress, Joomla et le système est parfaitement fonctionnel. A l'époque de Prestashop 1.5 (avec Varnish 3) j'étais arrivé à quelque chose de satisfaisant. Avec Prestashop 1.6, ce n'est pas le cas. Je vous propose de publier au fil de l'eau mes avancés concernant les fichiers VCL Bien entendu, si vous avez déjà obtenu des résultats, n'hésitez pas à publier vos éléments. Je mettrai en ligne des premiers éléments dans la journée. Cordialement Jerome Link to comment Share on other sites More sharing options...
Mephivio Posted May 31, 2014 Author Share Posted May 31, 2014 Hypothèse : environnement LAMP (php 5.3+ & Apache 2) Installation sur une base UBUNTU SERVER curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add - echo "deb http://repo.varnish-cache.org/ubuntu/ precise varnish-4.0" | sudo tee -a /etc/apt/sources.list sudo apt-get update sudo apt-get install varnish Edit du fichier Varnish - indiquer le port 80 (http) et la quantité de RAM octroyée à Varnish vi /etc/default/varnish # Should we start varnishd at boot? Set to "no" to disable. START=yes # Maximum number of open files (for ulimit -n) NFILES=131072 # Maximum locked memory size (for ulimit -l) # Used for locking the shared memory log in memory. If you increase log size, # you need to increase this number as well MEMLOCK=82000 DAEMON_OPTS="-a *:80 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s malloc,512m" Paramétrer APACHE en indiquant votre ip fixe vi /etc/apache2/ports.conf NameVirtualHost *:8080 NameVirtualHost <indiquer votre adresseip>:8080 Listen 8080 Listen 443 -> option, selon les installations et les panels, il faut vous rendre encore dans /etc/apache2/conf.d et vérifier que les différents fichiers conf contiennent le bon port de redirection à savoir 8080 Exemple : NameVirtualHost <indiquer votre adresse ip>:8080Listen <indiquer votre adresse ip>:8080NameVirtualHost <indiquer votre adresse ip>:8443Listen <indiquer votre adresse ip>:8443 Redémarrer l'ensemble pour vérifier le bon fonctionnement des différentes couches : service apache2 restart service varnish restart Link to comment Share on other sites More sharing options...
Mephivio Posted May 31, 2014 Author Share Posted May 31, 2014 Configuration de Varnish pour Prestashop 1.6 Attention - version de test non totalement finalisée, mais chacun d'entre nous y met un peu du sien, cela pourra aboutir à quelque chose de stable !!! Faites des tests avec GTmetrix avant et après : vous verrez déjà l'effet booster en route ! Tout se passe dans le fichier default.vcl qui se trouve dans /etc/varnish/default.vcl dont voici le contenu : # Marker to tell the VCL compiler that this VCL has been adapted to the# new 4.0 format.vcl 4.0;# Default backend definition. Set this to point to your content server.backend default { .host = <indiquer votre adresse ip>; .port = "8082"; .connect_timeout = 1s; .first_byte_timeout = 30s;}acl purge { "127.0.0.1"; "localhost"; "<indiquer votre adresse ip>";}sub vcl_recv { if (req.method == "PURGE") { if (!client.ip ~ purge) { return(synth(405,"Not allowed.")); } # jump to hit/miss return (purge); } # Handle IPv6 if (req.http.Host ~ "^ipv6.*") { set req.http.host = regsub(req.http.host, "^ipv6\.(.*)","www\.\1"); } 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; } } # remove double // in urls, set req.url = regsuball( req.url, "//", "/" ); # Properly handle different encoding types if (req.http.Accept-Encoding) { if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") { # No point in compressing these unset req.http.Accept-Encoding; } elsif (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; } elsif (req.http.Accept-Encoding ~ "deflate") { set req.http.Accept-Encoding = "deflate"; } else { # unkown algorithm unset req.http.Accept-Encoding; } } # Compatiblity with Apache log unset req.http.X-Forwarded-For; set req.http.X-Forwarded-For = client.ip; # Remove has_js and Google Analytics __* cookies. if (req.http.cookie) { set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", ""); # Remove a ";" prefix, if present. set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", ""); # Remove empty cookies. if (req.http.Cookie ~ "^\s*$") { unset req.http.Cookie; } } set req.backend_hint = default; # defaultif (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; }}# pipe on weird http methodsif (req.method !~ "^GET|HEAD|PUT|POST|TRACE|OPTIONS|DELETE$") { return(pipe);}if (req.method == "GET" && (req.url ~ "^/?mylogout=")) { unset req.http.Cookie; return (pass);}#we should not cache any page for Prestashop backendif (req.method == "GET" && (req.url ~ "^/admin")) { return (pass);}#we should not cache any page for customersif (req.method == "GET" && (req.url ~ "^/authentification" || req.url ~ "^/my-account")) { return (pass);}#we should not cache any page for customersif (req.method == "GET" && (req.url ~ "^/identity" || req.url ~ "^/my-account.php")) { return (pass);}#we should not cache any page for salesif (req.method == "GET" && (req.url ~ "^/cart.php" || req.url ~ "^/order.php")) { return (pass);}#we should not cache any page for salesif (req.method == "GET" && (req.url ~ "^/addresses.php" || req.url ~ "^/order-detail.php")) { return (pass);}#we should not cache any page for salesif (req.method == "GET" && (req.url ~ "^/order-confirmation.php" || req.url ~ "^/order-return.php")) { return (pass);}if (req.method != "GET" && req.method != "HEAD") { return (pass);}# Do not cache POST requestif (req.method == "POST") { return (pipe);}# Ignore empty cookiesif (req.http.Cookie ~ "^\s*$") { unset req.http.Cookie;}set req.url = regsub(req.url, "\.js\?.*", ".js");set req.url = regsub(req.url, "\.css\?.*", ".css");set req.url = regsub(req.url, "\.jpg\?.*", ".jpg");set req.url = regsub(req.url, "\.gif\?.*", ".gif");set req.url = regsub(req.url, "\.swf\?.*", ".swf");set req.url = regsub(req.url, "\.xml\?.*", ".xml");if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|pdf)$" && ! (req.url ~ "\.(php)") ) { unset req.http.Cookie; return (hash);}return (hash); } sub vcl_hash { hash_data(req.url); if (req.http.host) { hash_data(req.http.host); } else { hash_data(server.ip); } if (req.http.Cookie) { hash_data(req.http.Cookie); } # If the client supports compression, keep that in a different cache if (req.http.Accept-Encoding) { hash_data(req.http.Accept-Encoding); } return(lookup);}sub vcl_pass { set req.http.X-marker = "pass" ;}sub vcl_pipe { # Note that only the first request to the backend will have # X-Forwarded-For set. If you use X-Forwarded-For and want to # have it set for all requests, make sure to have: # set bereq.http.connection = "close"; # here. It is not set by default as it might break some broken web # applications, like IIS with NTLM authentication. #set bereq.http.Connection = "Close"; return (pipe);}sub vcl_backend_response { # Bypass cache for files > 10 MB if (std.integer(beresp.http.Content-Length, 0) > 10485760) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver); } if ( ! beresp.http.Content-Encoding ~ "gzip" ) { set beresp.do_gzip = true; } #unset beresp.http.expires; if (bereq.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|gz|rar|txt|bzip|pdf)$") { unset beresp.http.set-cookie; } if (beresp.ttl > 0s ) { if (beresp.status >= 300 && beresp.status <= 399) { set beresp.ttl = 10m; } if (beresp.status >= 399) { set beresp.ttl = 0s; } } if (beresp.status >= 399) { unset beresp.http.set-cookie; } # Maximum 24h de cache if (beresp.ttl > 86400s) { set beresp.ttl = 86400s; } if (bereq.http.X-marker == "pass" ) { unset bereq.http.X-marker; set beresp.http.X-marker = "pass"; set beresp.ttl = 0s ; } # Only allow cookies to be set if we're in admin area#if (beresp.http.Set-Cookie && bereq.url !~ "^/wp-(login|admin)") {# unset beresp.http.Set-Cookie;#}if (bereq.method == "GET" && (bereq.url ~ "^/?mylogout=")) { set beresp.ttl = 0s; unset beresp.http.Set-Cookie; set beresp.uncacheable = true; return(deliver);}# don't cache response to posted requests or those with basic authif ( bereq.method == "POST" || bereq.http.Authorization ) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver);}# don't cache search resultsif ( bereq.url ~ "\?s=" ){ set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver);}# only cache status okif ( beresp.status != 200 ) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver);}# no cacheif (beresp.http.X-No-Cache) { set beresp.uncacheable = true; set beresp.ttl = 120s; return (deliver);}set beresp.uncacheable = true;return (deliver); }sub vcl_deliver { if (obj.hits > 0){ set resp.http.X-Varnish-Cache = "HIT"; } else { set resp.http.X-Varnish-Cache = "MISS"; } if (resp.http.X-marker == "pass" ) { unset resp.http.X-marker; set resp.http.X-Varnish-Cache = "PASS"; } unset resp.http.Via; unset resp.http.X-Whatever; unset resp.http.X-Powered-By; unset resp.http.X-Varnish; unset resp.http.Age; unset resp.http.Server; set resp.http.X-Frame-Options = "SAMEORIGIN"; set resp.http.X-Xss-Protection = "1; mode=block";}sub vcl_synth { if (resp.status >= 500 && req.restarts < 4) { return (restart); }} Voila ! A vous de jouer ! Link to comment Share on other sites More sharing options...
FlexH Posted June 11, 2014 Share Posted June 11, 2014 Bonjour Jerome, Je viens de tester ton fichier de configuration sur un varnish4 et je n'ai malheureusement que des MISS ou des PASS. Quels résultats obtiens-tu ? Pour info, je suis sur un nginx + php-fpm. et presta 1.6. Cordialement, David. Link to comment Share on other sites More sharing options...
Mephivio Posted June 12, 2014 Author Share Posted June 12, 2014 bonjour cela dépends aussi de ton template et des modules que tu utilises pour ma part, j'ai effectivement encore pas mal de MISS (les pass sont comme demandé présents quand je suis dans le backoffice ou connecté sur un compte utilisateur sur le frontoffice, ce qui est normal). j'ai cependant aussi des hit je travaille à l'amélioration des résultats mais les tests sont longs l'idée est que chacun apporte sa pierre à l'édifice afin que nous arrivions au final à une solution stable et performante je travaille aussi à la propagation des bonnes adresses ip Par contre j'ai finalisé mon chantier pour wordpress et c'est nickel tu pourras toutefois remarquer que si tu testes ton site prestashop avec GTMETRIX que le niveau de perf général a toutefois bien progressé : pour ma part je suis passé à 95% cordialement Link to comment Share on other sites More sharing options...
HaCos Posted August 21, 2014 Share Posted August 21, 2014 Hello, Can you share more info for your presta installation? How was the load time before vanish and how is it now? How many concurrent users do you serve and whats your server specs? Thanks, C Link to comment Share on other sites More sharing options...
Paulo Ens Posted August 22, 2014 Share Posted August 22, 2014 Sorry to enter on a french conversation speaking english, but I think it's better for you then portuguese(my natural language). It's great to know you are trying to make Prestashop work with Varnish. I'm interested in start testing it too. Are all the Prestashop features working fine when running with Varnish or are you experiencing any kind of problems on your store? I tested on a store with Prestashop 1.4.8.2 and it was not allowing to add more then one product to the cart. It kept creating always a new cart with every product. That's why I'm asking if it's working on PS 1.6. Thanks, Link to comment Share on other sites More sharing options...
Mephivio Posted September 6, 2014 Author Share Posted September 6, 2014 Dear all, My tests with Varnish 4.0.1 are not closed i can't qualify prestashop having some troubles under varnish Concerning some CMS like Joomla or Wordpress, all works fine i don't know if the prestashop team works on the compatibilty with varnish but i'm coming back to you when i get a stable platform JP Link to comment Share on other sites More sharing options...
damien165 Posted October 17, 2014 Share Posted October 17, 2014 Bonjour, Avez-vous pu avancer sur le sujet? Damien Link to comment Share on other sites More sharing options...
jd440 Posted October 21, 2014 Share Posted October 21, 2014 As tu réussit à configurer correctement varnish? Sinon penses tu que même si le traffic n'est pas interessant le gain est non négligable ou seulement il interessant d'installer varnsih seulement pour les site à gros traffic? Link to comment Share on other sites More sharing options...
Mephivio Posted December 30, 2014 Author Share Posted December 30, 2014 Bonjour, J'ai repris mes tests cette fois-ci avec la dernière version varnish 4.02 (64 bit car l'éditeur ne supporte plus le mode 32-bit) Les bench AB montrent une croissance forte des capacités du VPS mais aussi les sites Wordpress, Joomla et Prestashop sont globalement plus rapides. c'est significatif Toutefois, sacré Prestashop - autant pour Wordpress + 1 concurrent de PS (Wo...) nickel Mais avec Prestashop, toujours des pb ... Je ne désespère pas. Si d'autres ont avancé sur les VCL, ce serait sympa de partager ! A vos plumes J Link to comment Share on other sites More sharing options...
jd440 Posted May 16, 2015 Share Posted May 16, 2015 Bonjour avez vous avancé sur vos varnish? Link to comment Share on other sites More sharing options...
sennevb Posted November 15, 2015 Share Posted November 15, 2015 Hi, I'm testing varnish on my website: Https://www.zelfbouw-domotica.be I used your config, and http://www.isvarnishworking.com/ says it is not working.If i take the default.vcl it is working, but not caching prestashop.. Any issues?? Link to comment Share on other sites More sharing options...
Lynda Posted October 17, 2020 Share Posted October 17, 2020 Bonjour, Je suis sur Prestashop 1.7.6.3, pensez-vous que je puisse activer le cache Varnish ? Merci. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now