vcl中定义调度器说明:
1. 轮询方式
backend appServer1 {
.host = "172.16.100.52";
.port = "80";
.probe = {
.url = "/test.html";
.expected_response = 200;
}
}
backend appServer2 {
.host = "172.16.100.53";
.port = "80";
}
import directors;
sub vcl_init {
new rr = directors.round_robin();
rr.add_backend(appServer1);
rr.add_backend(appServer2);
}
sub vcl_recv {
set req.backend_hint = rr.backend();
......
}
2. hash方式
backend appServer1 {
.host = "172.16.100.52";
.port = "80";
}
backend appServer2 {
.host = "172.16.100.53";
.port = "80";
}
import directors;
sub vcl_init {
new hash = directors.hash();
hash.add_backend(appServer1, 1.0);
hash.add_backend(appServer2, 1.0);
}
sub vcl_recv {
set req.backend_hint = hash.backend(req.http.X-Forwarded-For);
......
}
说明:当varnish前端用nginx做反代时,在nginx中需要做如下配置:
proxy_pass http://varnish_server_ip:port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
网友评论