centos5.x
varnish2.0.6
#yum install epel-release
#yum install varnish
#/usr/sbin/groupadd www -g 444
#/usr/sbin/useradd -u 444 -g www www
#mkdir -p /var/vcache
#chmod +w /var/vcache
#chown -R www:www /var/vcache
ls /etc/varnish
#This is a basic VCL configuration file for varnish. See the vcl(7)#man page for details on VCL syntax and semantics.
#
#Default backend definition. Set this to point to your content
#server.
#
backend default {
.host = "192.168.20.211";
.port = "80";
}
acl purge {
"localhost";
"127.0.0.1";
"192.168.20.0"/24;
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
lookup;
}
if (req.http.host ~ "^www.abc.com") {
set req.backend = default;
if (req.request != "GET" && req.request != "HEAD") {
pipe;
}
else {
lookup;
}
}
else {
error 404 "Cache Server";
lookup;
}
}
sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
error 404 "Not in cache.";
}
}
sub vcl_fetch {
if (req.request == "GET" && req.url ~ "/.(txt|js)$") {
set obj.ttl = 3600s;
}
else {
set obj.ttl = 30d;
}
}
#/usr/sbin/varnishd -n /var/vcache -f /etc/varnish/vcl.conf -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on
#whereis varnishncsa
查看日志可 以看到:/usr/bin/varnishncsa -n /var/vcache -w /var/logs/varnish.log &
#vi /etc/rc.local
/usr/sbin/varnishd -n /var/vcache -f /etc/varnish/vcl.conf -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on
/usr/bin/varnishncsa -n /var/vcache -w /var/logs/varnish.log &