HAProxy +清漆configurationbuild议

我正在使用HAProxy来平衡一堆PHP服务器,并且现在要在场景中引入Varnish。
如果app-login cookie不可用,HAP发送请求给Varnish,Varnish在这里除了服务请求(Cache HIT)或者把它发回HAP之外的Cache MISS,HAP然后select一个PHP服务器和资源被取出并由HAP通过清漆送达客户。 我有以下configuration文件。
这里我不明白2件事。

  1. 在高速caching未命中的情况下清漆给请求返回到HAP,检查应用程序logincookie,没有find它,并将其发回清漆(结束less循环的情况),我可以让Varnish设置一个cookie,并使HAP检查并在此基础上selectPHP服务器后端(build议欢迎)。
  2. 其次,如何在MISS中获取资源的时候通过HAP获取资源,然后将其发送给客户端,这样Varnish最终可以build立caching。

请让我知道是否有一些关键的东西在这里错过了。

提前致谢

configuration文件

#BE for Varnish is HAP in this machine backend default { .host = "127.0.0.1"; .port = "80"; } sub vcl_recv { # HAP sends request to Varnish iff app-login cookie is not available # Varnish doesnt have to do anything here except to serve request(Cache HIT) or # send it back to HAP incase of Cache MISS, resouces are then fetched from PHP servers # and served to client by HAP through Varnish # We unset the cookies here as they dont affect the response unset req.http.cookie; # Lighttpd is already compressing resources, so we dont do it here. return (lookup); # Control is passed to vcl_hit or vcl_miss } sub vcl_hit { return (deliver); } sub vcl_miss { return (fetch); } sub vcl_fetch { set obj.ttl = 1m; return (deliver); } sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } return (deliver); } sub vcl_init { return (ok); } sub vcl_fini { return (ok); } 

感谢Baptiste Assmann,我能够得到第2点的响应。我问 – 一旦PHP服务器回答HAProxy,响应会沿着相反的path,所以响应通过Varnish(所以它被caching)然后传回HAProxy,然后返回到HAProxy客户。

对于第一点,我提到的循环条件(再次感谢Baptiste)可以通过在HAPconfiguration中将ACL传递给PHP服务器(我使用Varnish的IP作为条件)来解决,所以当caching未命中时,HAP获取来自Varnish的请求,获取资源并遵循相反的path,然后去Varnish去HAP,最后去用户。 我testing了这个条件,HAP日志清楚地表明它正在工作:

 108.108.108.108:21478 [08/Jan/2013:11:58:16.**637**] inbound varnish/varnish0 1/0/0/1803/2182 200 45872 – - —- 2/2/0/1/0 0/0 {abc.xxx.com} “GET / HTTP/1.1″ 192.168.1.1:37029 [08/Jan/2013:11:58:16.**639**] inbound worker/worker0 0/0/0/1796/1802 200 45776 – - –NI 2/2/0/1/0 0/0 {abc.xxx..com} “GET / HTTP/1.1″ 

调用来HAP,因为cookie不可用HAP将其发送到清漆,发生caching未命中,worker0用于通过HAP获取资源。 在下一个调用(我caching1米)清漆服务的一切从caching(varnishlog告诉我这一点)和PHP服务器没有联系。

谢谢