centos下安装varnish
时间:2017-04-05 22:34 来源:linux.it.net.cn 作者:IT
-
1,下载安装包,并修改文件名
-
wget http://sourceforge.net/projects/varnish/files/latest/download
-
tar zxvf download
-
cd varnish-2.1.3
-
2,安装相关组件pcre
-
yum install pcre
-
3,设置环境变量
-
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
-
4,配置
-
./configure --prefix=/usr/local/varnish --enable-dependency-trackin --enable-debugging-symbols --enable-developer-warnings
-
5,编译安装
-
make &&make install
-
6,启动
-
./../../sbin/varnishd -f /usr/local/varnish/etc/varnish/varnish.vcl -s file,/var/varnish_cache,1G -T 127.0.0.1:2000 -a 0.0.0.0:9001
示例配置
-
[root@localhost varnish]# cat varnish.vcl
-
backend cqserver {
-
.host = "192.168.0.1";
-
.port = "5007";
-
.connect_timeout = 20s;
-
}
-
acl purge {
-
"localhost";
-
"127.0.0.1";
-
"192.168.1.0"/24;
-
}
-
sub vcl_recv {
-
if (req.request == "PURGE") {
-
if (!client.ip ~ purge) {
-
error 405 "Not allowed.";
-
}
-
return (lookup);
-
}
-
-
if (req.http.host ~ "^192") {
-
set req.backend = cqserver;
-
if (req.request != "GET" && req.request != "HEAD") {
-
return (pipe);
-
}
-
else{
-
return (lookup);
-
}
-
}
-
else {
-
error 404 "caoqing Cache Server";
-
return (lookup);
-
}
-
}
-
sub vcl_hit {
-
if (req.request == "PURGE") {
-
set obj.ttl = 0s;
-
error 200 "Purged.";
-
}
-
}
-
-
sub vcl_deliver {
-
if (obj.hits > 0){
-
set resp.http.X-Cache = "HIT";
-
} else {
-
set resp.http.X-Cache = "MISS";
-
}
-
}
-
-
sub vcl_miss {
-
if (req.request == "PURGE") {
-
error 404 "Not in cache.";
-
}
-
}
(责任编辑:IT)
示例配置
(责任编辑:IT) |