haproxy + varnish cache配置

varnish配置

vi /etc/varnish/vcl.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
backend default

 {

        set backend.host = "192.168.1.118"
;
        set backend.port = "80"
;
}

 
sub vcl_recv {

        # pass mode can't handle POST (yet)

        if

 (req.request == "POST"
) {

                pipe;
        }

 
        # force lookup even when cookies are present
        #if

 (req.request == "GET"
 && req.http.cookie) {

        #        lookup;
        #}

        #静态文件CACHE
        if

 (req.request == "GET"
 && req.url ~ "/.(gif|jpg|swf|css|js)$"
) {

                lookup;
        }

}

 
sub vcl_fetch {

        # force minimum ttl of 180 seconds
        if

 (obj.ttl < 180s) {

                set obj.ttl = 180s;
        }

}

 



haproxy 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000
 
listen webfarm 0.0.0.0:80
       mode http
       stats uri /haproxy-stats
       stats realm Haproxy/ statistics
       stats auth another:another
       balance roundrobin
       cookie SERVERID insert indirect
       option httpchk HEAD /ha_check.html HTTP/1.0
       server webA 127.0.0.1:8080 cookie A check



启动varnish.sh:

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
# file: start.sh
date -u
varnishd /
-a 127.0.0.1:8080 /
-s file,/var/cache/varnish/V,1024m /
-f /etc/varnish/vcl.conf /
-p thread_pool_max=1500 /
-p thread_pools=5 /
-p listen_depth=512 /
-p client_http11=on /



附varnish多站点配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
backend www {

       set backend.host = "www.chinajavaworld.com"
;
       set backend.port = "80"
;
         }

 
backend blog {

       set backend.host = "blog.chinajavaworld.com"
;
       set backend.port = "80"
;
         }

 
backend image {

      set backend.host = "image.chinajavaworld.com"
;
      set backend.port = "80"
;
         }

 
sub vcl_recv {

      if

 (req.http.host ~ "^(www.)?chinajavaworld.com$"
) {

            set req.http.host = "www.chinajavaworld.com"
;
            set req.backend = www;
      }
 elsif (req.http.host ~ "^blog.chinajavaworld.com$"
) {

            set req.backend = blog;
      }
 elsif (req.http.host ~ "^image.chinajavaworld.com$"
) {

            set req.backend = image;
      }
 else

 {

            error 404 "Unknown host"
;
}



附varnish in OpenSuse安装

1
2
rpm -ivh libvarnish0-1.1-3.2.i586.rpm
rpm -ivh varnish-1.1-3.2.i586.rpm



Get rpm from
http://download.opensuse.org/repositories/server:/http/openSUSE_10.3/i586

平均得分
(0 次评分)




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值