• 首页
    • English
    • 中文
  • 关于我们
  • 服务项目
    • 谷歌SEO服务
    • WordPress建站服务
    • 谷歌ADS/SEM代运营
  • 项目案例
    • 医疗
    • 建材
    • 机械加工
    • 照明
    • 电商
    • 电脑硬件
  • 博客
    • 服务器运维
      • aliyun
      • 服务器安装
      • 宝塔面板
      • 虚拟化
      • 阿里云
      • Centos
      • linux
      • nginx
    • 电子商务
    • 免费资源
    • PHP
      • Magento
      • WordPress
    • 大数据采集
    • Python
    • Javascript
    • SEO
    • 未分类
  • 联系我们
What's Hot

机械模具加工公司网站设计案例

24 10 月, 2023

快速原型公司案例

24 10 月, 2023

陶瓷加工网站案例

24 10 月, 2023
Facebook Twitter Instagram
  • 中文
  • English
Facebook Twitter Instagram
VPSEO VPSEO
  • 首页
    • English
    • 中文
  • 关于我们
  • 服务项目
    • 谷歌SEO服务
    • WordPress建站服务
    • 谷歌ADS/SEM代运营
  • 项目案例
    • 医疗
    • 建材
    • 机械加工
    • 照明
    • 电商
    • 电脑硬件
  • 博客
    • 服务器运维
      • aliyun
      • 服务器安装
      • 宝塔面板
      • 虚拟化
      • 阿里云
      • Centos
      • linux
      • nginx
    • 电子商务
    • 免费资源
    • PHP
      • Magento
      • WordPress
    • 大数据采集
    • Python
    • Javascript
    • SEO
    • 未分类
  • 联系我们
VPSEO VPSEO
Home»Uncategorized»Varnish 4 VCL for Prestashop 1.6
Uncategorized

Varnish 4 VCL for Prestashop 1.6

chrispengcnBy chrispengcn7 8 月, 2021没有评论6 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email

Hi, Prestashop Community Members. I’ve been recently playing with Varnish 4 as an attempt to reduce my Prestashop 1.6 site’s loading time. So far so good, the loading time have now decreased to ~1.5s and decided to share my VCL with the community so that we can create a big-single VCL configuration file for Varnish 4  for performance, security and a high hit-rate with the feedback from the whole community.

 

Varnish 4 VCL for Prestashop v0.2 (Updated on May 06th, 2016):

 

#

# This is an example VCL file for Varnish.

#

# It does not do anything by default, delegating control to the

# builtin VCL. The builtin VCL is called when there is no explicit

# return statement.

#

# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/

# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.




# 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 = "127.0.0.1";

    .port = "8080";

}




sub vcl_recv {

  # Only deal with "normal" types

  if (req.method != "GET" &&

      req.method != "HEAD" &&

      req.method != "PUT" &&

      req.method != "POST" &&

      req.method != "TRACE" &&

      req.method != "OPTIONS" &&

      req.method != "PATCH" &&

      req.method != "DELETE") {

    /* Non-RFC2616 or CONNECT which is weird. */

    return (pass);

  }

  # Only cache GET or HEAD requests. This makes sure the POST requests are always passed.

  if (req.method != "GET" && req.method != "HEAD") {

    return (pass);

  }

 # Some generic URL manipulation, useful for all templates that follow

  # First remove the Google Analytics added parameters, useless for our backend

  if (req.url ~ "(?|&)(utm_source|utm_medium|utm_campaign|utm_content|gclid|cx|ie|cof|siteurl)=") {

    set req.url = regsuball(req.url, "&(utm_source|utm_medium|utm_campaign|utm_content|gclid|cx|ie|cof|siteurl)=([A-z0-9_-.%25]+)", "");

    set req.url = regsuball(req.url, "?(utm_source|utm_medium|utm_campaign|utm_content|gclid|cx|ie|cof|siteurl)=([A-z0-9_-.%25]+)", "?");

    set req.url = regsub(req.url, "?$", "");

  }




  # Strip a trailing ? if it exists

  if (req.url ~ "?$") {

    set req.url = regsub(req.url, "?$", "");

  }




  # Strip hash, server doesn't need it.

  if (req.url ~ "#") {

    set req.url = regsub(req.url, "#.*$", "");

  }




if (req.http.Accept-Encoding) {

    # Do no compress compressed files...

    if (req.url ~ ".(jpg|png|gif|woff2|gz|tgz|bz2|tbz)$") {

          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 {

      unset req.http.Accept-Encoding;

    }

  }

# Remove the "has_js" cookie

  set req.http.Cookie = regsuball(req.http.Cookie, "has_js=[^;]+(; )?", "");




  # Remove any Google Analytics based cookies

  set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");

  set req.http.Cookie = regsuball(req.http.Cookie, "_ga=[^;]+(; )?", "");

  set req.http.Cookie = regsuball(req.http.Cookie, "_gat=[^;]+(; )?", "");

  set req.http.Cookie = regsuball(req.http.Cookie, "utmctr=[^;]+(; )?", "");

  set req.http.Cookie = regsuball(req.http.Cookie, "utmcmd.=[^;]+(; )?", "");

  set req.http.Cookie = regsuball(req.http.Cookie, "utmccn.=[^;]+(; )?", "");




  # Remove DoubleClick offensive cookies

  set req.http.Cookie = regsuball(req.http.Cookie, "__gads=[^;]+(; )?", "");




  # Remove the Quant Capital cookies (added by some plugin, all __qca)

  set req.http.Cookie = regsuball(req.http.Cookie, "__qc.=[^;]+(; )?", "");




  # Remove the AddThis cookies

  set req.http.Cookie = regsuball(req.http.Cookie, "__atuv.=[^;]+(; )?", "");




  # Remove a ";" prefix in the cookie if present

  set req.http.Cookie = regsuball(req.http.Cookie, "^;s*", "");




  # Are there cookies left with only spaces or that are empty?

  if (req.http.cookie ~ "^s*$") {

    unset req.http.cookie;

}




#we should not cache any page for sales

if (req.method == "GET" && (req.url ~ "^/cart.php" || req.url ~ "^/order.php")) {

    return (pass);

}

#we should not cache any page for sales

if (req.method == "GET" && (req.url ~ "^/addresses.php" || req.url ~ "^/order-detail.php")) {

    return (pass);

}

#we should not cache any page for sales

if (req.method == "GET" && (req.url ~ "^/order-confirmation.php" || req.url ~ "^/order-return.php")) {

    return (pass);

}

if (req.url ~ "^[^?]*.(css|js|jpg|png|gif|woff|woff2)(?.*)?$") {

    unset req.http.Cookie;

  }

if (req.http.Authorization || req.http.Authenticate)

{

  return (pass);

}

}




sub vcl_backend_response {

# Avoid Header Expires in the past

if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {

    unset beresp.http.set-cookie;

    unset beresp.http.Expires;

    set beresp.ttl = 24h;

    unset beresp.http.Cache-Control;

    # Set new Cache-Control headers for browsers to store cache for 7 days

    set beresp.http.Cache-Control = "public, max-age=604800";

    set beresp.http.magicmarker = "1";

    set beresp.http.cachable = "1";

        if (bereq.url !~ ".(css|js|jpg|png|gif|woff|woff2|html|htm|gz)(?|$)") {

            set beresp.http.Pragma = "no-cache";

            set beresp.http.Expires = "-1";

            set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";

            set beresp.grace = 1m;

        }

        return(deliver);

        }

  # Sometimes, a 301 or 302 redirect formed via Apache's mod_rewrite can mess with the HTTP port that is being passed along.

  # This often happens with simple rewrite rules in a scenario where Varnish runs on :80 and Apache on :8080 on the same box.

  # A redirect can then often redirect the end-user to a URL on :8080, where it should be :80.

  # This may need finetuning on your setup.

  #

  # To prevent accidental replace, we only filter the 301/302 redirects for now.

  if (beresp.status == 301 || beresp.status == 302) {

    set beresp.http.Location = regsub(beresp.http.Location, ":[0-9]+", "");

  }




  # Don't cache 50x responses

  if (beresp.status == 500 || beresp.status == 502 || beresp.status == 503 || beresp.status == 504) {

    return (abandon);

  }




  # Allow stale content, in case the backend goes down.

  # make Varnish keep all objects for 1 hour beyond their TTL

  set beresp.grace = 1h;




  return (deliver);

}




sub vcl_deliver {

if(obj.hits > 0) {

     set resp.http.X-Cache = "HIT";

  } else {

    set resp.http.X-Cache = "MISS";

  }

  # Remove some headers: PHP version

  unset resp.http.X-Powered-By;

  # Remove some headers: Apache version & OS

  unset resp.http.Server;

  # Remove some heanders: Varnish

  unset resp.http.Via;

  unset resp.http.X-Varnish;

}

Edited May 6, 2016 by moy2010 (see edit history)

https://www.prestashop.com/forums/topic/525145-varnish-4-vcl-for-prestashop-16/

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
chrispengcn
  • Website

Related Posts

Nginx做负载均衡,有没有办法碰到404就跳过?

2 7 月, 2022

如何快速把多个excel表合并成一个excel表

7 8 月, 2021

nginx配置泛域名转发到子目录nginx泛域名转发到泛域名

7 8 月, 2021

wordpress如何防止发布文章时候自动清除

、
换行标签

7 8 月, 2021
Add A Comment

Leave A Reply Cancel Reply

*

code

导航
  • 首页
  • 关于我们
  • 服务项目
  • 项目案例
  • 博客文章
  • 联系我们
博客
  • 服务器运维
  • 服务器安装
  • nginx
  • PHP
  • WordPress
  • Python
  • Javascript
  • SEO
  • 电子商务
  • 大数据采集
  • 宝塔面板
  • 数据库
  • 电子商务
  • 虚拟化
  • 阿里云
导航
  • 首页
  • 关于我们
  • 谷歌SEO服务
  • 谷歌ADS/SEM代运营
  • WordPress建站服务
  • 项目案例
  • 博客
  • 联系我们
最新文章
  • 机械模具加工公司网站设计案例
  • 快速原型公司案例
  • 陶瓷加工网站案例
  • CNC数控加工日文网站案例
  • 触摸一体机数字标牌厂家网站案例
关于我们
关于我们

广州纬来科技有限公司
联系地址:广东省广州市番禺区富华中路富源二街18号合和大厦809

QQ : 13602156
Email : 13926026058@139.com
Contact: +86 13926026058

Facebook Twitter YouTube LinkedIn
© 2025 广州纬来科技有限公司 粤ICP备2023105857号-2
  • 首页
  • 关于我们
  • 谷歌SEO服务
  • 谷歌ADS/SEM代运营
  • WordPress建站服务
  • 项目案例
  • 博客
  • 联系我们

Type above and press Enter to search. Press Esc to cancel.