当前位置: 首页 » 产品 » 微商货源 » 正文

WordPress在CentOS服务器下如何安装Varnish加速

放大字体  缩小字体 发布日期: 2024-09-30 09:31   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:26
核心提示:  Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸Verdens Gang ()使用3台Varnish代替了原来的12台squid,性能居然

  Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸Verdens Gang () 使用3台Varnish代替了原来的12台squid,性能居然比以前更好。可见Varnish是一个相当强大的加速器。下面罗伊给大家介绍如何在 CentOS上安装Varnish来给你的WordPress博客加速。

  1,安装Varnsih

  使用SSH登录你的VPS,执行下面的命令来安装Varnish:

  yum install varnish

  然后我们启动Varnish:

  /etc/init.d/varnish start

  设置为开机启动:

  chkconfig –level 345 varnish on

  2,配置Varnish

  打开default.vcl:

  nano /etc/varnish/default.vcl

  确认默认的default.vcl和下面的代码相匹配:

  # Back-End backend default { .host="127.0.0.1"; .port="80"; .connect_timeout=60s; .first_byte_timeout=10s; .between_bytes_timeout=10s; } # Custom sub vcl_recv { remove req.http.X-Forwarded-For; set req.http.X-Forwarded-For=client.ip; if (req.url ~ "^/wp-(login|admin)") { return (pipe); } if (req.http.cookie ~"(wp-postpass|wordpress_logged_in|comment_author_)") { return (pipe); } if (req.request=="POST") { return (pass); } if (req.http.Cache-Control ~ "no-cache") { return (pass); } if (req.http.Authorization) { return (pass); } if (req.url ~ ".(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pd f|txt|tar|wav|bmp|rtf|js|flv|swf|htm|html)$") { unset req.http.cookie; unset req.http.Accept-Encoding; unset req.http.Vary; return (lookup); } if (req.http.Accept-Encoding) { if (req.url ~ ".(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { remove 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 { remove req.http.Accept-Encoding; } } if (req.backend.healthy) { set req.grace=30s; } else { set req.grace=1h; } unset req.http.cookie; unset req.http.Vary; return (lookup); } sub vcl_fetch { set beresp.grace=1h; unset beresp.http.set-cookie; if (req.url ~ ".(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pd f|txt|tar|wav|bmp|rtf|js|flv|swf|htm|html)$") { set beresp.ttl=24h; } else { set beresp.ttl=5m; } return (deliver); } sub vcl_deliver { if(obj.hits > 0) { set resp.http.X-Cache="HIT"; } else { set resp.http.X-Cache="MISS"; } set resp.http.Cache-Control="private"; set resp.http.Pragma="private"; remove resp.http.X-Varnish; remove resp.http.Via; remove resp.http.Age; remove resp.http.Server; remove resp.http.X-Powered-By; } sub vcl_pipe { set bereq.http.connection="close"; } 重启Varnish使其生效: /etc/init.d/varnish restart

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站