Varnish安装搭建配置缓存服务器
Varnish特点:安装 配置 简单,支持后端服务器的负载均衡和健康检查,URL地址重写。
官方下载地址:
yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
cd varnish-2.1.4
./configure --prefix=/usr/local/varnish
make && make install
简单配置文件:cat /usr/local/varnish/etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "9999";
}
#定义后端应用端口
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
return (lookup);
}
return (pass);
}
#图片、swf等静态文件设置缓存,其他类型文件pass到后端.
sub vcl_pipe {
set bereq.http.connection = "close";
return (pipe);
}
sub vcl_pass {
return (pass);
}
启动Varnish:
查看状态:
查看Referer:
查看访问路径:
官方下载地址:
wget http://www.varnish-software.com/sites/default/files/varnish-2.1.4.tar.gz
标准安装:
yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
cd varnish-2.1.4
./configure --prefix=/usr/local/varnish
make && make install
简单配置文件:cat /usr/local/varnish/etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "9999";
}
#定义后端应用端口
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
return (lookup);
}
return (pass);
}
#图片、swf等静态文件设置缓存,其他类型文件pass到后端.
sub vcl_pipe {
set bereq.http.connection = "close";
return (pipe);
}
sub vcl_pass {
return (pass);
}
启动Varnish:
/usr/local/varnish/sbin/varnishd -f /usr/local/varnish/etc/varnish/default.vcl -s malloc,128M -T 127.0.0.1:2500 -a 0.0.0.0:80
查看状态:
/usr/local/varnish/bin/varnishstat
查看Referer:
/usr/local/varnish/bin/varnishtop -i rxheader -I Referer
查看访问路径:
/usr/local/varnish/bin/varnishtop -i rxurl
相关推荐
丁丁爸爸的技术 2020-03-04
王继敏 2020-01-15
huangzonggui 2020-01-18
leodengzx 2020-01-14
83374255 2011-08-23
87530399 2011-05-07
qlf00 2014-08-08
strburnchang 2015-04-03
阿赞 2012-11-13
zhangpuego 2011-12-05
haoxun0 2015-10-13
Caleb0 2015-09-04
蜀川居 2015-04-05
musicman 2013-06-07
阳光之吻 2019-06-21
lunhuishizhe 2013-09-10
零度源码 2012-07-13
whosemario 2011-10-17
tianshijianbing 2018-11-04