2016-05-15 62 views
1

我使用的清漆3后面的代理多个网站到一个域。 基本设置工作正常,但我现在有一个问题,如果文件名已存在于它的缓存中,清漆会提供错误的文件。 基本上所有我在default.vcl做的是:清漆服务错误的文件

if(req.url ~ "^/foo1") { 
     set req.backend = foo1; 
     set req.url = regsub(req.url, "^/foo1/", "/"); 
    } 
    else if(req.url ~ "^/foo2") { 
     set req.backend = foo2; 
     set req.url = regsub(req.url, "^/foo2/", "/"); 
    } 

如果我现在请/foo1/index.html,/foo2/index.html将服务于同一个文件。重新启动清漆并调用/foo2/index.html后,/ foo1/index.html将为foo2的index.html提供服务。

至于我发现这是创作不尊重使用后端,但只有网址(缩短)之后的散列的问题和领域:

11 VCL_call  c hash 
    11 Hash   c /index.html 
    11 Hash   c mydomain 

我解决了这个问题现在通过改变我的vcl_hash也使用的后端,但我敢肯定,必须有一个更好的,更方便的方法:

sub vcl_hash { 
     hash_data(req.url); 
     hash_data(req.backend); 
    } 

任何暗示将不胜感激,非常感谢你!

回答

1

你有两种不同的方式来做到这一点。首先,通过在vcl_hash中增加额外的值(例如req.backend)来执行您的建议。

sub vcl_hash { 
    hash_data(req.url); 
    hash_data(req.backend); 
} 

第二种方式是不更新vcl_recvreq,但只有在vcl_miss/passbereq

sub vcl_urlrewrite { 
    if(req.url ~ "^/foo1") { 
     set bereq.url = regsub(req.url, "^/foo1/", "/"); 
    } 
    else if(req.url ~ "^/foo2") { 
     set bereq.url = regsub(req.url, "^/foo2/", "/"); 
    } 
} 
sub vcl_miss { 
    call vcl_urlrewrite; 
} 
sub vcl_pass { 
    call vcl_urlrewrite; 
} 
sub vcl_pipe { 
    call vcl_urlrewrite; 
} 

第二种方法需要更多的VCL,但它也具有优势。例如,在分析日志varnishlog时,可以看到vanilla请求(c列)以及更新的后端请求(b列)。

$ varnishlog /any-options-here/ 
(..) 
    xx RxURL  c /foo1/index.html 
(..) 
    xx TxURL  c /index.html 
(..) 
$ 
+0

谢谢!第二种方法看起来很好,只是经过测试! – deveth0