0
내 웹 사이트에 기본 default.vcl이 있었는데 작동했습니다.바니시 {default.vcl}에 모바일 감지 기능을 추가 한 후 바니쉬가 시작되지 않음
pc 또는 모바일 양식을 사용하는 경우 사용자에게 다른 테마를 감지하고 제공하기 위해 아래 코드를 추가했습니다. 모바일 장치를 감지하기 위해 아래 코드를 추가 한 후 바니시가 시작되지 않습니다. 나는이 그렇게 니스를 해결하려면 어떻게
은 당신이 니스를 시작하려고 할 수있는 모바일 장치와 모바일에서 방문 할 때 너무 모바일 테마가 동일한 URL에서 제공됩니다, 테이블
/*
*
* First, set up a backend to answer the request if there's not a cache hit.
*
*/
backend default {
# Set a host.
.host = "xx.xx.xx.xx";
# Set a port. 80 is normal Web traffic.
.port = "xxxx";
}
/*
*
* Next, configure the "receive" subroutine.
*
*/
acl admin_ip {
"xx.xx.xx.xx";
}
include "devicedetect.vcl";
sub vcl_recv {
call devicedetect;
if (req.request == "PURGE") {
if (!client.ip ~ admin_ip) {
error 405 "You can't do this, muggle!";
}
return(lookup);
}
if (!req.backend.healthy) {
unset req.http.Cookie;
}
set req.http.X-Forwarded-For = client.ip;
# Use the backend we set up above to answer the request if it's not cached.
#set req.backend = default;
if (req.url ~ "^/user/login" ||
req.url ~ "^/oc-admin" ||
req.url ~ "^/item/new" ||
req.request == "POST")
{
return (pass);
}
if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\?.*)?$") {
unset req.http.Cookie;
unset req.http.Cache-Control;
unset req.http.Max-Age;
unset req.http.Pragma;
unset req.http.Cookie;
}
if(req.http.Cookie) {
if (req.http.Cookie !~ "(sessionid|XXXid)") {
remove req.http.Cookie;
}
}
# Pass the request along to lookup to see if it's in the cache.
return(lookup);
}
/*
*
* Next, let's set up the subroutine to deal with cache misses.
*
*/
sub vcl_miss {
# We're not doing anything fancy. Just pass the request along to the
# subroutine which will fetch something from the backend.
return(fetch);
}
/*
*
* Now, let's set up a subroutine to deal with cache hits.
*
*/
sub vcl_hit {
# Again, nothing fancy. Just pass the request along to the subroutine
# which will deliver a result from the cache.
return(deliver);
}
/*
*
* This is the subroutine which will fetch a response from the backend.
* It's pretty fancy because this is where the basic logic for caching is set.
*
*/
sub vcl_fetch {
if (req.http.X-UA-Device) {
if (!beresp.http.Vary) { # no Vary at all
set beresp.http.Vary = "X-UA-Device";
} elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary
set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
}
}
#unset beresp.http.expires; # for cloudfront since it prefers cache-control
# header over expires
if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\?.*)?$") {
unset beresp.http.set-cookie;
}
if (req.http.Content-Type ~ "(image|audio|video|pdf|flash)") {
set beresp.do_gzip = false;
}
if (req.http.Content-Type ~ "text") {
set beresp.do_gzip = true;
}
# Varnish determined the object was not cacheable
if (beresp.ttl 0) {
set resp.http.X-Varnish-Cache = "HIT";
}
else {
set resp.http.X-Varnish-Cache = "MISS";
}
return (deliver);
}
위의 명령을 사용한 후이 명령을 사용하면
# Varnish determined the object was not cacheable if (beresp.ttl 0) { set resp.http.X-Varnish-Cache = "HIT"; } else { set resp.http.X-Varnish-Cache = "MISS"; }
에 오류가 있음을 보여 주므로이 (beresp.ttl 0 = (beresp.ttl> = 0s)로 바꾸고 바니시를 시작한 것 하지만 아무것도 cahing되지 않습니다 –장치 감지 vcl은 [링크] (https://github.com/varnishcache/varnish-devicedetect/blob/master/devicedetect.vcl)입니다. –