- 论坛徽章:
- 0
|
本帖最后由 小黑别被黑 于 2013-02-16 16:17 编辑
首先说明一下,使用虚拟机安装centos 6 64位
Varnish版本3.0.0/3.0.2 Nginx版本1.0.6
Varnish:172.2.2.108
Nginx:172.2.2.109
本地PC hosts文件中已经设置:
172.2.2.108 www.t1.com(通过varnish访问)
172.2.2.109 www.t2.com(通过nginx访问)
varnish启动后,通过nginx访问
在浏览器中输入www.t2.com,可正常访问
通过varnish访问时:
在浏览器中输入www.t1.com,会出现问题,问题是:第一次访问的时一直在load,始终打不开一直load,如果点下刷新就立刻显示页面,但是当你再次访问的时候又出现第一次打开时的情况,再一刷新立刻又可以了!
各位大神都遇到过这个问题吗?换了2.0.x的版本任然有这个问题
下面是我的vcl配置:
backend t1 {
.host = "172.2.2.109";
.port = "80";
}
#
# Below is a commented-out copy of the default VCL logic. If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
sub vcl_recv {
if (req.request == "GET" && req.url ~ "\.(jpg|png|gif|swf|flv|ico|jpeg)$") {
unset req.http.cookie;
}
if (req.request =="GET"&&req.url ~ "(?i)\.php($|\?)"){
return (pass);
}
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.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
return (pass);
}
if (req.http.host ~ "(?i)(www.t1.com)") {
set req.backend = t1;
set req.http.host = "www.t1.com";
if (req.request != "GET" && req.request != "HEAD") {
return(pipe);
}
}
return (lookup);
}
sub vcl_pipe {
return (pipe);
}
sub vcl_pass {
return (pass);
}
sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (hash);
}
#
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "purged";
}
return (deliver);
}
#
sub vcl_miss {
if(req.request == "PURGE") {
error 404 "not in cache.";
}
return (fetch);
}
#
sub vcl_fetch {
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
/*
* Mark as "Hit-For-Pass" for the next 2 minutes
*/
set beresp.ttl = 120 s;
return (hit_for_pass);
}
if (beresp.http.Pragma ~ "no-cache" ||
beresp.http.Cache-Control ~ "no-cache" ||
beresp.http.Cache-Control ~ "private") {
return(deliver);
}
if(beresp.status == 404 || beresp.status == 300) {
error 404;
}
if (req.request == "GET" && req.url ~ "\.(jpg|png|gif|swf|flv|ico|jpeg)$") {
set beresp.ttl = 1d;
}
if (req.request == "GET" && req.url ~ "\.(htm|html)$") {
set beresp.ttl = 1d;
}
# if (req.url ~ "\.(png|gif|jpg)$") {
# unset beresp.http.set-cookie;
# set beresp.ttl = 1h;
# }
return (deliver);
}
#
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "cached";
} else {
set resp.http.x-Cache = "uncached";
}
unset resp.http.X-Powered-By;
unset resp.http.Server;
return (deliver);
}
sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
set obj.http.Retry-After = "5";
synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} + obj.status + " " + obj.response + {"</title>
</head>
<body>
<h1>Error "} + obj.status + " " + obj.response + {"</h1>
<p>"} + obj.response + {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} + req.xid + {"</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
"};
return (deliver);
}
sub vcl_init {
return (ok);
}
sub vcl_fini {
return (ok);
}
综合飞鸿无痕与CyaLiven提出的问题继续请教,在线等 |
|