backend images {
set backend.host = "images.example.com";
set backend.port = "80";
}
sub vcl_recv {
if (req.http.host ~ "^()?example.com$") {
set req.backend = www;
} elsif (req.http.host ~ "^images.example.com") {
set req.backend = images;
} else {
error 404 "Unknown virtual host";
}
}
#关于cache存在时间设置
sub vcl_fetch {
if (obj.ttl < 120s) {
set obj.ttl = 120s;
}
}
#cache图片等内容配置
sub vcl_recv {
if (req.request == "GET" && req.url ~ "\.(gif|jpg||jpeg|tom|swf|css|js)$") {
lookup;
}
lookup;
}
5.关于服务器 param的设置
param有以下选项
user root (0)
group root (0)
default_ttl 14400 [seconds]
thread_pools 1 [pools]
thread_pool_max 12000 [threads]
thread_pool_min 4000 [threads]
thread_pool_timeout 10 [seconds]
overflow_max 100 [%]
http_workspace 8192 [bytes]
sess_timeout 5 [seconds]
pipe_timeout 60 [seconds]
send_timeout 20 [seconds]
auto_restart on [bool]
fetch_chunksize 128 [kilobytes]
sendfile_threshold unlimited [bytes]
vcl_trace off [bool]
listen_address 172.16.189.1:3128
listen_depth 1024 [connections]
srcaddr_hash 1049 [buckets]
srcaddr_ttl 720 [seconds]
backend_http11 on [bool]
client_http11 on [bool]
ping_interval 3 [seconds]
大家可以使用-p参数在启动时候进行配置和优化
例如
/home/admin/varnish/sbin/varnishd -f /etc/varnish/vcl.conf \
-a 172.16.189.1:3128 \
-s malloc \
-p user root -p group root \
-p default_ttl 14400 -p thread_pool_max 8000 -p send_timeout 20 \
-p srcaddr_ttl 720 -p backend_http11 on -p client_http11 on \
-w 4000,12000,10 -T 127.0.0.1:8080
6.关于varnishd的管理
管理功能的启用需要在启动varnishd的时候 启动 -T参数指定 telnet管理使用的地址和端口
使用telnet localhost 8080,然后输入help参看相关的管理选项
或者使用 /home/admin/varnishd/bin/varnishadm -T localhost:8080 cmd进行管理
使用/home/admin/varnishd/bin/varnishstat 来查看varnishd的运行情况
7.关于log
使用home/admin/varnishd/bin/varnishlog 和varnishncsa查看服务器访问log或者让其输出到文件来记录log
Varnish 的详细介绍:请点这里
Varnish 的下载地址:请点这里
相关阅读:
CentOS 5.8下Varnish-2.1.5的安装配置
RedHat脚本改用CentOS源更新安装Nginx、PHP 5.3、Varnish