Varnish动静分离配置示例
Posted liming-linux-python
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Varnish动静分离配置示例相关的知识,希望对你有一定的参考价值。
动静分离
[[email protected] ~]# vim /etc/varnish/default.vcl
vcl 4.0;
backend web {
.host = "192.168.30.153";
.port = "80";
.probe = {
.url = "/check.html";
}
}
backend img {
.host = "192.168.30.131";
.port = "80";
.probe = {
.url = "/check.html";
}
}
sub vcl_recv {
if (req.url ~ "(?i).(jpg|png|gif)$") {
set req.backend_hint = img;
} else {
set req.backend_hint = web;
}
}
[[email protected] ~]# echo $HOSTNAME > /usr/share/nginx/html/check.html
[[email protected] ~]# echo $HOSTNAME > /usr/share/nginx/html/check.html
[[email protected] ~]# varnishadm ‘vcl.load v1 default.vcl‘
[[email protected] ~]# varnishadm ‘vcl.use v1‘
[[email protected] ~]# varnishadm ‘vcl.list‘
[[email protected] ~]# varnishadm ‘backend.list‘ # 健康检查8次,8次均成功
略
[[email protected] ~]# for i in {1..9};do echo "$i.html on $HOSTNAME" > /usr/share/nginx/html/$i.html;done
[[email protected] ~]# for i in {1..9};do echo "$i.jpg on $HOSTNAME" > /usr/share/nginx/html/$i.jpg;done
[[email protected] ~]# curl varnish.example.com/1.html
1.html on web.example.com
[[email protected] ~]# curl varnish.example.com/1.jpg
1.jpg on img.example.com
以上是关于Varnish动静分离配置示例的主要内容,如果未能解决你的问题,请参考以下文章
CentOS 7.1.1503 varnish动静分离反代用户请求
高可用haproxy调度varnish服务器缓存后端动静分离集群架构
haproxy+varnish实现discuz论坛的动静分离以及静态缓存