wordpress的varnish内存级缓存方案
varnish是优秀的缓存服务器,配置简单,命中率高,性能高效.
下面我们以wordpress博客程序为例看看如何配置varnish.
1、首先安装好web环境,可以使用本站的LNMP一键安装包配置.
2、安装varnish.
1 | rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm |
下载default.vcl文件覆盖 /etc/varnish/default.vcl文件. http://centos.googlecode.com/files/default.vcl
3、修改varnish配置文件 /etc/varnish/default.vcl:
1 | backend default { |
8080端口是后缀nginx或apache的端口.
1 | # Only cache the following site |
这个是只允许localhost缓存,需要改成自己的wordpress域名.
1 | [.........] |
这个是设置缓存页面过期时间为1h,单位可以是s(秒),h(小时),d(天)等.
4、修改 /etc/sysconfig/varnish配置文件: 重要的有两个值:
1 | VARNISH_LISTEN_PORT=80 定义varnish的端口为80. |
5、管理varnish的命令
1 | service varnish start(restart|reload) 进程的启动,重启,配置重载. |
6、最后需要安装wordpress清除varnish缓存的插件wordpress varnish: 可以在后台搜索,也可以直接下载http://wordpress.org/extend/plugins/wordpress-varnish/. 经过简单的六步,就完全了wordpress varnish缓存的配置.